RFR: JDK-8234634: JShell could leverage the better NullPointerException analysis

Jan Lahoda jan.lahoda at oracle.com
Fri Nov 22 10:52:09 UTC 2019


Hi,

Maurizio suggested on core-libs-dev that JShell could leverage the 
better NullPointerException analysis. This patch tried to do it. The 
outcome for the user is e.g.:
---
jshell> String s = null;
s ==> null

jshell> s.length()
|  Exception java.lang.NullPointerException: Cannot invoke 
"String.length()" because "s" is null
|        at (#2:1)

jshell> String test(Object o) { return o.toString(); }
|  created method test(Object)

jshell> test(null)
|  Exception java.lang.NullPointerException: Cannot invoke 
"Object.toString()" because "o" is null
|        at test (#3:1)
|        at (#4:1)
---

There are three parts of this patch:
1. enabling -g:vars, so that the NPE analysis has more data to work on
2. enabling -XX:+ShowCodeDetailsInExceptionMessages, so that the 
enhanced analysis runs. It feels a little bit unfortunate to depend on a 
non-standard VM option, but this is only done in the tool (not in the 
engine), so it may be OK.
3. processing of the NPE message to strip references to the synthetic 
JShell classes.

Webrev: http://cr.openjdk.java.net/~jlahoda/8234634/webrev.00/
JBS: https://bugs.openjdk.java.net/browse/JDK-8234634

How does this look?

Thanks,
     Jan


More information about the kulla-dev mailing list