question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

null values and addConcreteSettersForOptional

See original GitHub issue

I 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:closed
  • Created a year ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
Randgaltcommented, Apr 20, 2022

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.

1reaction
Randgaltcommented, Apr 20, 2022

@Randgalt it doesn’t even make since to have methods with javax.validation.constraints (your gist you shared on reddit showing full builder) unless you immediately call the validator. In fact the requireNonNull on justAString is wrong

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found