r/java • • Jul 26 '19

JEP 358: Helpful NullPointerExceptions

https://openjdk.java.net/jeps/358
157 Upvotes

25 comments sorted by

View all comments

-29

u/__konrad Jul 27 '19

NullPointerException should be deprecated for removal

5

u/thatsIch Jul 27 '19

May to incline why? This sounds rather unuseful.

7

u/dpash Jul 27 '19 edited Jul 27 '19

Reducing the ability for things to be null would be useful. Kotlin has non-nullablity baked into the type system. The best we can currently do in Java is to use annotations to get static checker warnings. We can not make variables non-null by default because that would break existing code; we could add optional non-nullablity in the future. Inline classes will be non-null from what I understand, so that's a step in the right direction.

Fewer nulls means fewer NPEs but we'll never get rid of it, if only because we have to deal with old code to deal with.

10

u/thatsIch Jul 27 '19

This rather sounds like the removal of null instead of removing NPE (which would be a side-effect) but not sure how a migration of Java to a non-null world would look like.

10

u/dpash Jul 27 '19

Yes, that's exactly the case. Removing NPE without removing null would be impossible.

0

u/[deleted] Jul 27 '19

[deleted]

11

u/dpash Jul 27 '19

By the same argument, we don't need strong type systems. We just need to be better at our jobs.

0

u/[deleted] Jul 27 '19

[deleted]

9

u/dpash Jul 27 '19

The straw man was arguing against the complete removal of null when I never claimed such a thing.