Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java 14 nullpointerexception no detailed message

Java 14 has many new features. One of them is showing detailed message in NullPointerException. I installed Java 14 and trying to compile and run below class but I am not getting any detailed message. Am I missing anything? please help.

~/code/demo/temp$ java -version
openjdk version "14" 2020-03-17
OpenJDK Runtime Environment AdoptOpenJDK (build 14+36)
Eclipse OpenJ9 VM AdoptOpenJDK (build openj9-0.19.0, JRE 14 Mac OS X amd64-64-Bit Compressed          References 20200313_47 (JIT enabled, AOT enabled)
OpenJ9   - 0133ba037
OMR      - 1c04e0ef9
JCL      - a73be60649 based on jdk-14+36)

~/code/demo/temp$ cat Hello.java
public class Hello {
  public static void main(String args[]) {
    String a = null;
    System.out.println(a.length());
  }
}

~/code/demo/temp$ javac Hello.java
~/code/demo/temp$ java -XX:+ShowCodeDetailsInExceptionMessages Hello
Exception in thread "main" java.lang.NullPointerException
at Hello.main(Hello.java:4)

I am passing suggested -XX:+ShowCodeDetailsInExceptionMessages flag to java but there is no detailed message. Please help.

like image 370
Pradeep Avatar asked Mar 15 '26 23:03

Pradeep


1 Answers

OpenJ9 currently does not support JEP 358:

Extended messages for NullPointerException not yet implemented

JEP 358: Helpful NullPointerExceptions provides extended messages when a NullPointerException is generated by the Java 14 VM and you have enabled the feature. However, be aware that this is not implemented in OpenJ9 at this time.

The progress is tracked in this bug

If you want to use this feature, download the hotspot variant from adoptopenjdk. It's the same vendor as your current distribution, so this is only a small change.

like image 176
Johannes Kuhn Avatar answered Mar 17 '26 12:03

Johannes Kuhn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!