Skip to content

albihasani94/helpful-NPE

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Helpful NPE

JEP 358: https://openjdk.java.net/jeps/358.

Use flag -XX:+ShowCodeDetailsInExceptionMessages.

Requires JDK 14.

Compile

javac -d classes src/com/albi/helpful/npe/App.java

Run

java -XX:+ShowCodeDetailsInExceptionMessages -cp classes/ com/albi/helpful/npe/App

Alternatively, make a jar

mkdir target

jar --create --file=target/helpful-npe.jar --main-class=com.albi.helpful.npe.App -C classes .

java -XX:+ShowCodeDetailsInExceptionMessages -jar target/helpful-npe.jar

Comparison

Before

Exception in thread "main" java.lang.NullPointerException
	at com.albi.helpful.npe.App.printCharFromStringAt(App.java:16)
	at com.albi.helpful.npe.App.main(App.java:12)

After

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.charAt(int)" because "text" is null
	at com.albi.helpful.npe.App.printCharFromStringAt(App.java:16)
	at com.albi.helpful.npe.App.main(App.java:12)

About

JEP 358: Helpful NullPointerExceptions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages