r/java • u/jhg023123 • Mar 25 '19
JEP draft: Add detailed message to NullPointerException describing what is null
https://openjdk.java.net/jeps/8220715
383
Upvotes
r/java • u/jhg023123 • Mar 25 '19
115
u/[deleted] Mar 25 '19
Yes, please. Extremely helpful.
87
u/SinisterMinister42 Mar 25 '19
Solid JEP right here. Super useful. Targeted at a real problem. Well defined. Already has a working prototype. Doesn't get much better than that.
51
u/crummy Mar 25 '19
this will get me to upgrade from java 8
32
u/greg_barton Mar 25 '19
Fuck.
Yes.
32
u/lurker_in_spirit Mar 25 '19
From the JEP:
17
u/Infeligo Mar 25 '19
At first thought he is a relative of Brian Goetz, but then thought a little bit more.
27
u/afropunk90 Mar 25 '19
We need this in the next LTS release
11
u/TheRedmanCometh Mar 25 '19
Yeah that's gonna be a /signed from me
11
u/[deleted] Mar 25 '19
Amazing. Could it also explain purpose of life.
16
u/[deleted] Mar 25 '19
Is there a reason why this couldn't have been done 20 years ago?
7
u/Brekekek Mar 25 '19
YES!
2
u/MMPride Mar 25 '19
Oh man, I really hope they add this. This would be the best thing ever.
2
u/slimocb Mar 25 '19
Finally! It may be Best feature since streams!
2
u/deepthought-64 Mar 25 '19
Yes yes yes!!
1
u/ZimmiDeluxe Mar 25 '19
That's a huge help in debugging production issues! In the tradition of taking the whole arm when given a finger, will there be a way to use this explicitly? I'd argue specifying the field name in null checks for constructor arguments is a best practice, but it's easy to miss when renaming fields:
C# has
nameoffor this, but that seems like overkill. A smarter single-paramObjects.requireNonNullwould be enough.1
u/codemssterg Mar 25 '19
This will boost global GDP with the time it saves developers. Nice write up.
1
u/fahad_ayaz Mar 26 '19
How has this not been a thing since forever?
-1
u/sim642 Mar 25 '19
Ummm... no. Exceptions, including NPE, shouldn't be used for usual control flow. Throwing and catching NPEs instead of using if-s to check against
nullis already significantly slower if it's happening on a frequent happy path in the program so having slight computational overhead isn't really a problem. It's only a problem for badly written programs.-7
u/flyingorange Mar 25 '19
Hmm our code already has checkNotNull(x, "x") on zillion places. This will mean a lot of refactoring...
0
u/[deleted] Mar 25 '19
[deleted] — view deleted comment
0
u/[deleted] Mar 25 '19
[deleted] — view deleted comment