0

Recently, I have had trouble comparing LocalDateTime instances using the predefined method isAfter().

I have tried the following in Eclipse and it works fine:

stock.getReserveDate().isAfter(LocalDateTime.now())

where stock is a JPA Entity with a LocalDateTime field that has a getter called getReserveDate().

Executing the following code in JSP(which I believe is identical to the line above) gives me a NullPointerException.

<c:when test="${!compStock.getReserveDate().isAfter(LocalDateTime.now())}"> <p>Stock is reserved!</p> </c:when>

After debugging, I've managed to find out that the LocalDateTime.now() part of my code is considered null by JSP / JSTL but I have no idea why. This code works perfectly when ran in Eclipse but fails in a JSP.

Ole V.V.
  • 65,573
  • 11
  • 96
  • 117
Pete
  • 31
  • 6
  • That shouldn’t be possible. `LocalDateTime.now()` returns “the current date-time using the system clock and default time-zone, not null”. Note: „not null“. If you’re sure, consider adding [a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – Ole V.V. Mar 31 '19 at 07:00
  • I have found a workaround and I know, its not a good practice, but I am open to ideas. We import the `LocalDateTime` class into JSP by using `` and the code above starts working. – Pete Mar 31 '19 at 09:53
  • That import sounds more to me like the correct solution than like a workaround. @Pete – Ole V.V. Mar 31 '19 at 10:43

0 Answers0