Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#297 Add rules for Java 1.8's new type Optional

3.0.0
closed-fixed
Java 1.8 (2)
5
2014-06-27
2014-04-17
Nicolai Parlog
No

Since 1.8 Java has a type Optional which might or might not contain a not-null value. Best practice is to never use null where an Optional should be used (e.g. if a method's return type is Optional it shouldn't return null) and always call isPresent() before calling get() (similar to the annotation CheckForNull).

It would be nice to have FinBugs-rules which enforce this practice.

Related

Feature Requests: #302

Discussion

  • Nicolai Parlog
    Nicolai Parlog
    2014-05-14

    Thank you, Andrey.
    Any headway on the rule "call isPresent() before get()"?

     
    • status: open --> closed-fixed
    • assigned_to: Andrey Loskutov
    • Group: 2.1.0 --> 3.0.0
     
  • Please create second ticket for the rule: "always call isPresent() before calling get() (similar to the annotation CheckForNull)."