JDK-14 Exception Details Feature : Add More Details To Your NullPointerException
JDK-14 provides a new ability to developer for checking root cause of a NullPointerException.
So instead of getting only code line number as a root cause of your NullPointerException, like :
[pastacode lang=”java” manual=”public%20static%20void%20main(String%5B%5D%20args)%20%7B%0A%20%20%20%20%20%20%20%20String%20mystring%20%3D%20null%3B%0A%0A%20%20%20%20%20%20%20%20System.out.println(mystring.toString())%3B%0A%20%20%20%20%7D%0A%0A%0AException%20in%20thread%20%22main%22%20java.lang.NullPointerException%0A%09at%20YourClass.main(your_class.java%3A5)” message=”Old NullPointerException” highlight=”” provider=”manual”/]
From JDK-14 You are can get more details about a NullPointerException by adding the following argument on VM Options :
[pastacode lang=”java” manual=”-XX%3A%2BShowCodeDetailsInExceptionMessages” message=”New VM Argument for more exception details” highlight=”” provider=”manual”/]
Result after applying this change :
[pastacode lang=”markup” manual=”public%20static%20void%20main(String%5B%5D%20args)%20%7B%0A%20%20%20%20%20%20%20%20String%20mystring%20%3D%20null%3B%0A%0A%20%20%20%20%20%20%20%20System.out.println(mystring.toString())%3B%0A%20%20%20%20%7D%0A%0A%0AException%20in%20thread%20%22main%22%20java.lang.NullPointerException%3A%20Cannot%20invoke%20%22String.toString()%22%20because%20%22mystring%22%20is%20null%0A%09at%20YourClass.main(your_class.java%3A5)” message=”After adding new ShowCodeDetailsInExceptionMessages argument” highlight=”” provider=”manual”/]
Java/JavaEE (Hybris/Spring) & Full Stack Senior Developer
I’m passionate about new technologies or any kind of thing that change our lifestyle to better either by automatisation of existing process or creating new solution.