JSP not throwing NullPointerException JSP not throwing NullPointerException spring spring

JSP not throwing NullPointerException


Not sure if a StackOverflow wiki on Expression Language is a trustworthy reference (I've been trying to find it in the official specs, no luck yet), but:

EL relies on the JavaBeans specification when it comes to accessing properties. In JSP, the following expression:

${user.name}

does basically the same as the following in "raw" scriptlet code (the below example is for simplicity, in reality the reflection API is used to obtain the methods and invoke them):

<%  User user = (User) pageContext.findAttribute("user");  if (user != null) {    String name = user.getName();    if (name != null) {      out.print(name);    }  }%>

(...) Please note that it thus doesn't print "null" when the value is null nor throws a NullPointerException unlike as when using scriptlets. In other words, EL is null-safe.


In model.addAttribute("railwayService",railwayServiceRepository.findOne(id));

whenever value is null, it will not throw NullPointerException, It will just pass value as null to the view.