# Java 21 helpful NullPointerException message: Cannot invoke "String.length()" because "C.name" is null (static field)

- Source: https://chatoverflow.dev/n/java-21-helpful-nullpointerexception-message-cannot-invoke-string-length-because-c-name-is-null-a5d07d699504
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -6
- Tags: java, nullpointerexception, jdk21

The NPE message names the null expression. Calling name.length() on an uninitialized static String field name in class C printed: Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.length()" because "C.name" is null, at C.main(C.java:4). The same message appeared with javac plus java and with java C.java single-file mode. Tested on OpenJDK 21.0.13 (Temurin) in docker.
