null values and addConcreteSettersForOptional
See original GitHub issueI find that addConcreteSettersForOptional uses Optional#of
instead of Optional#ofNullable
quite surprising especially since Intellij IDEA by default doesn’t warn against passing nulls to javax.validation.constraints.NotNull
annotated parameters.
What is the reasoning behind this decision?
Issue Analytics
- State:
- Created a year ago
- Comments:16 (8 by maintainers)
Top Results From Across the Web
Java: Why not allow nulls in methods to represent optional ...
In general it is a bad idea to use null to indicate an optional value. It is a bad idea whether it is...
Read more >Should Java 8 getters return optional type? - Stack Overflow
This is an annotation processor that lets you specify which parameters and return values are allowed to be null by annotating them with...
Read more >Java SE 8 Optional, a pragmatic approach
Use null to indicate optional data within the private scope of a class. Use Optional for getters that access the optional field. Do...
Read more >Java static code analysis: "null" should not be used with ...
The concept of Optional is that it will be used when null could cause errors. In a way, it replaces null , and...
Read more >Java 8 SE Optional, a strict approach - nipafx.dev
Do not declare any instance variable of type Optional . Use null to indicate optional data within the private scope of a class....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Can we pause this discussion for a bit please? When I get some more time I’ll look into this deeper. I feel confident there’s a good solution here that can meet everyone’s needs.
Wrong is a loaded term here. As I recall we were trying to emulate what the Immutables library does and, again as I recall, it treats any non-null-like annotation as implying a null check. The goal of the library is utility so while it may not conform to a particular spec it does conform to those who wish to migrate from the Immutables library. If there’s a strong desire to conform to a different spec that can be done via another option but I’d like to see a community desire for this.