Skip to content

[GR-66205] Native images don't print "Helpful NullPointerExceptions" (JEP 358) #9680

@zakkak

Description

@zakkak

Describe the issue
JVM prints:

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.length()" because "HelloWorld.name" is null
	at HelloWorld.main(HelloWorld.java:6)

while the corresponding native image prints:

Exception in thread "main" java.lang.NullPointerException
	at HelloWorld.main(HelloWorld.java:6)

Steps to reproduce the issue

cat > HelloWorld.java <<EOF                                                                                                                                                                     
public class HelloWorld {

    static final String name = null;

    public static void main(String[] args) {
        System.out.println("Hello world! " + name.length());
    }

}
EOF
javac HelloWorld.java
java HelloWorld
native-image -cp ./ HelloWorld
./helloworld

Describe GraalVM and your environment:

  • GraalVM version (latest snapshot builds can be found here), or commit id if built from source: a5ce3a7
  • JDK major version: 24+3
  • OS: Fedora 40
  • Architecture: AMD64

More details
Originally reported in quarkusio/quarkus#43274

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions