I had the same nasty annoyance about Glassfish 4 throwing NPEs on that kind of (wannabe) EL boolean evaluations:
<c:if test="${couldNotExistVar}">
Usage scenario for couldNotExistVar
:
- if some condition
- inquire flag
- inquire flag
- ...
JSP + JSTL + EL example:
<c:if test="${ obj.someExpensiveCalculation }">
<c:set var="couldNotExistVar" value="true" scope="request" />
</c:if>
As a solution I found best for me to add this first line:
<c:set var="imSureExistsVar" value="false" scope="request" />
<c:if test="${ obj.someExpensiveCalculation }">
<c:set var="imSureExistsVar" value="true" scope="request" />
</c:if>
Disadvantage:
- When using this kind of pattern it's easy to forget to include that
new extra line.
Be aware that the NPEs could only be detectable out of development environment if one uses a different (and even with the same Java EE version) application server that does not respond as Glassfish 4.