---
# System prepended metadata

title: NullPointerException
tags: [Note]

---

---

robots: index, follow
lang: zh-tw
dir: ltr
breaks: true
title: NullPointerException     # 簡報的名稱
tags: Note  # 簡報的標籤

---

# java.lang.NullPointerException: null
``` gherkin=
public List<Map<String, Object>> getWarehouseProcessList(List<Long> statusList, Long executorId, String startTime, String endTime) throws ParseException{
        Date startDate = sdf.parse(startTime);
        Date endDate = sdf.parse(endTime);
        return packageMainRepository.getWarehouseProcessList(statusList, executorId, startDate, endDate);
    }
``` 
### 發生 exception 處理方式
``` gherkin=
public List<Map<String, Object>> getWarehouseProcessList(List<Long> statusList, Long executorId, String startTime, String endTime) throws ParseException{
        Date startDate = startTime != null ? sdf.parse(startTime) : null;
        Date endDate = endTime != null ? sdf.parse(endTime) : null;
        }
```        
```gherkin=
public List<Map<String, Object>> getWarehouseProcessList(List<Long> statusList, Long executorId, String startTime, String endTime) throws ParseException{
        Date startDateTime = ( ( StringUtils.isNotBlank(startTime) ) ? simpleDateFormat.parse(startTime) : null );
        Date endDateTime = ( ( StringUtils.isNotBlank(endTime) ) ? simpleDateFormat.parse(endTime) : null );
        }
```
