Eu tinha aberto um tipoco onde enfrentava um problema referente a filtrar usando LocalDate, eu consegui resolver o problema do filtro com ajuda do professor. Contudo agora quando acesso o endpoint para listar todos os cadastros estou recebendo um erro de NullPointerException.
Codigo do endpoint:
@GetMapping
public Page<TransacaoDto> lista(@RequestParam(required = false) String data,
@PageableDefault(sort = "id", direction = Direction.DESC, page = 0, size = 10) Pageable paginacao) {
dataDaTransacao = LocalDate.parse(data, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
if(data == null) {
Page<Transacao> transacao = transacaoRepository.findAll(paginacao);
return TransacaoDto.converter(transacao);
}else {
Page<Transacao> transacao = transacaoRepository.findByDataDaTransacao(dataDaTransacao, paginacao);
return TransacaoDto.converter(transacao);
}
}
Pagina de erro do navegador:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Aug 01 08:55:23 BRT 2019
There was an unexpected error (type=Internal Server Error, status=500).
text
java.lang.NullPointerException: text
at java.util.Objects.requireNonNull(Unknown Source)
at java.time.format.DateTimeFormatter.parse(Unknown Source)
at java.time.LocalDate.parse(Unknown Source)
Erro no console:
java.lang.NullPointerException: text
at java.util.Objects.requireNonNull(Unknown Source) ~[na:1.8.0_191]
at java.time.format.DateTimeFormatter.parse(Unknown Source) ~[na:1.8.0_191]
at java.time.LocalDate.parse(Unknown Source) ~[na:1.8.0_191]
at com.bytebank.gestaodegastos.controller.TransacoesController.lista(TransacoesController.java:48) ~[classes/:na]
at com.bytebank.gestaodegastos.controller.TransacoesController$$FastClassBySpringCGLIB$$229b8edd.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:684) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at com.bytebank.gestaodegastos.controller.TransacoesController$$EnhancerBySpringCGLIB$$8cb1f5fa.lista(<generated>) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_191]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_191]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_191]