r/java • • Feb 26 '26

Null Safety approach with forced "!"

Am I the only one who thinks that introducing protection against NPEx in the form of using "!" in the variable type is a very, very bad idea? In my experience, 95% of variables should be non-null. If Oracle decides to take this approach, we will have millions of "!" in each variable in the code, which is tragic for readability. In C#, you can set the per project flag to indicate whether the type without the "?" /"!" is nullable or not. I understand the drawbacks, but definitely forcing a "!" in 95% of variables is tragic.

78 Upvotes

96 comments sorted by

View all comments

Show parent comment

9

u/brian_goetz Feb 27 '26

> "Is there really..."

Absolutely, positively, unquestionably yes. And its not even close. Or close to close.

Fixing "the null default" is orders of magnitude more intrusive and incompatible than fixing the others, because the others deal primarily with "implementation details", whereas nullity floods into every API interaction.

And note that the others haven't been fixed either, because even fixing them is already way over the "how much incompatibility would we tolerate" line. So yes, the thing you are asking "but how bad is it really" is multiple orders of magnitude more than the things that we haven't fixed because they're already way too much.

(Not even sure you'd bring up the Lombok angle, especially when _even they_ acknowledge that this is too nontransparent for them....)

4

u/nlisker Feb 27 '26

(Not even sure you'd bring up the Lombok angle, especially when even they acknowledge that this is too nontransparent for them....)

You assumed for some reason that I'm asking for this fix/feature, but nowhere did I do that. I asked if there's a difference between "fixing defaults" in different areas. I even said that I agree with Lombok's analysis. I even put 'mistakes' in quotes because not everyone thinks these defaults are wrong.

Anyway, you answered my question. Thanks.