detailed error message in NPE,java14 feature
I think Almost every Java developer At some pointed in our life would have encountered with NPE in java, and what’s worse then getting NPE is that stack trace only gives you the line number where it occurred so you gotta debug it further to check which part /variable of your expression caused it.

Let’s take an example.

Integer x= y*z \\Line 10

If above line throws a NPE then it could be because either y or z is null and we won’t know it until we debug it .And for much more complex expression it becomes more difficult.

So what’s new in Java 14?

Since Java 14, NPE will have a detailed message in its stack trace . JVM throws a NPE whenever code tries to dereference a null reference, the JVM will determine precisely which variable was null , and describe the variable (in terms of source code) with a null-detail message in the NPE. The null-detail message will then be shown in the JVM's message, alongside the method, filename, and line number.

Error message is going to have two part, first part will contain consequence(What failed because of NPE) and second part will consist of reason for NPE. Let us understand it with a better example.

For the expression doFoo().b[i][j] = 99; where doFoo() is an static method in a class named as Foo , If doFoo().b[i] is null then error message would be something like this “Cannot store to int array because Foo.doFoo().b[i] is null” .

Detail null-message is by default disabled in java14 ,we can enable it by command line argument -XX:+ShowCodeDetailsInExceptionMessages .

But the question becomes why would they keep it disabled by default ?Why wouldn’t anyone want to have such an amazing feature? Here are few reason for that.
[]
['Java', 'Npe', 'Java14', 'Programming', 'Java14 Features']