The “new” Nullpointer Exception in Java 17

As a java developer everyone should know the Nullpointer Exception or NPE. It is that one thing, you always should try to prevent from happening. In some cases it means that you need to debug your code to find the little mistake that happened.
The NPE…

As a java developer everyone should know the Nullpointer Exception or NPE. It is that one thing, you always should try to prevent from happening. In some cases it means that you need to debug your code to find the little mistake that happened.
The NPE is a runtime exception which is thrown when your code wants to use an object or an object reference that has a null value. That can be if simply no value is assigned or a object is without reference.

Before the newest version of the openJdk (version 17) the common Nullpointer Exception looked something like this in your stack-trace:

java.lang.NullPointerException: null

Probably theres much more on you stack-trace going on but this is it.
As you can see it does not indicate where or why your npe occurred.

Help is on the way!
Watch how Java 17 Handles this:

Exception in thread "main" java.lang.NullPointerException:
Cannot assign field "i" because "a" is null
at Prog.main(Prog.java:5)

In this example the exception pinpoints out where and what our null object reference is.

Just that simple!

As all of my posts this was also written on my private blog where i try to write useful posts for developers.

Or just follow me on twitter or dm me

Cheers!


Print Share Comment Cite Upload Translate
APA
| Sciencx (2024-03-29T11:16:31+00:00) » The “new” Nullpointer Exception in Java 17. Retrieved from https://www.scien.cx/2021/10/19/the-new-nullpointer-exception-in-java-17/.
MLA
" » The “new” Nullpointer Exception in Java 17." | Sciencx - Tuesday October 19, 2021, https://www.scien.cx/2021/10/19/the-new-nullpointer-exception-in-java-17/
HARVARD
| Sciencx Tuesday October 19, 2021 » The “new” Nullpointer Exception in Java 17., viewed 2024-03-29T11:16:31+00:00,<https://www.scien.cx/2021/10/19/the-new-nullpointer-exception-in-java-17/>
VANCOUVER
| Sciencx - » The “new” Nullpointer Exception in Java 17. [Internet]. [Accessed 2024-03-29T11:16:31+00:00]. Available from: https://www.scien.cx/2021/10/19/the-new-nullpointer-exception-in-java-17/
CHICAGO
" » The “new” Nullpointer Exception in Java 17." | Sciencx - Accessed 2024-03-29T11:16:31+00:00. https://www.scien.cx/2021/10/19/the-new-nullpointer-exception-in-java-17/
IEEE
" » The “new” Nullpointer Exception in Java 17." | Sciencx [Online]. Available: https://www.scien.cx/2021/10/19/the-new-nullpointer-exception-in-java-17/. [Accessed: 2024-03-29T11:16:31+00:00]
rf:citation
» The “new” Nullpointer Exception in Java 17 | | Sciencx | https://www.scien.cx/2021/10/19/the-new-nullpointer-exception-in-java-17/ | 2024-03-29T11:16:31+00:00
https://github.com/addpipe/simple-recorderjs-demo