-
Notifications
You must be signed in to change notification settings - Fork 93
Add AnnotateNullableMethods recipe
#364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add AnnotateNullableMethods recipe
#364
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java
- lines 35-35
- src/main/java/org/openrewrite/staticanalysis/UseCollectionInterfaces.java
- lines 28-28
- lines 59-60
src/main/java/org/openrewrite/staticanalysis/AnnotateNullableMethods.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/AnnotateNullableMethodsTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/AnnotateNullableMethodsTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/AnnotateNullableMethodsTest.java
Outdated
Show resolved
Hide resolved
e295fc3 to
4a6a356
Compare
4a6a356 to
8bf01d4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java
- lines 35-35
- src/main/java/org/openrewrite/staticanalysis/UseCollectionInterfaces.java
- lines 28-28
- lines 59-60
src/test/java/org/openrewrite/staticanalysis/AnnotateNullableMethodsTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/AnnotateNullableMethodsTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/AnnotateNullableMethodsTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java
- lines 35-36
src/test/java/org/openrewrite/staticanalysis/AnnotateNullableMethodsTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/AnnotateNullableMethodsTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/AnnotateNullableMethodsTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/AnnotateNullableMethodsTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/AnnotateNullableMethodsTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/AnnotateNullableMethodsTest.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/AnnotateNullableMethods.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/AnnotateNullableMethods.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/AnnotateNullableMethods.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/AnnotateNullableMethods.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Tim te Beek <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java
- lines 35-36
src/test/java/org/openrewrite/staticanalysis/AnnotateNullableMethodsTest.java
Outdated
Show resolved
Hide resolved
|
Hi @timtebeek I see that in your suggested change you have moved the |
Pankraz76
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leverage functional style and existing APIs over boilerplate imperative approaches to maximize code efficiency and readability.
src/main/java/org/openrewrite/staticanalysis/AnnotateNullableMethods.java
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/AnnotateNullableMethods.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/AnnotateNullableMethods.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/AnnotateNullableMethods.java
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/AnnotateNullableMethods.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/AnnotateNullableMethods.java
Outdated
Show resolved
Hide resolved
…ethodsTest.java Co-authored-by: Tim te Beek <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java
- lines 35-36
src/test/java/org/openrewrite/staticanalysis/AnnotateNullableMethodsTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Tim te Beek <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java
- lines 35-36
src/test/java/org/openrewrite/staticanalysis/AnnotateNullableMethodsTest.java
Outdated
Show resolved
Hide resolved
13907c2 to
21873f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java
- lines 35-36
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java
- lines 35-36
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java
- lines 35-36
src/main/java/org/openrewrite/staticanalysis/AnnotateNullableMethods.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java
- lines 35-36
src/main/java/org/openrewrite/staticanalysis/AnnotateNullableMethods.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java
- lines 35-36
src/main/java/org/openrewrite/staticanalysis/AnnotateNullableMethods.java
Outdated
Show resolved
Hide resolved
…ethods.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java
- lines 35-36
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java
- lines 35-36
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java
- lines 35-36
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java
- lines 35-35
timtebeek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great to see! Would you might once more running it against OpenRewrite from your IDE as a preview, and then once we merge this run it through the Moderne platform across all OpenRewrite repositories & created PRs to add these missing annotations and potentially resolve any nullability issues that then can reported downstream.
| methodDeclaration.getMethodType() == null || | ||
| methodDeclaration.getMethodType().getReturnType() instanceof JavaType.Primitive || | ||
| service(AnnotationService.class).matches(getCursor(), NULLABLE_ANNOTATION_MATCHER) || | ||
| service(AnnotationService.class).matches(new Cursor(null, methodDeclaration.getReturnTypeExpression()), NULLABLE_ANNOTATION_MATCHER)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once that's no longer yellow we can merge. :)



What's changed?
The PR implements the recipe outlined in #328. The new recipe will automatically add a
@org.jspecify.annotation.Nullableto non-private methods that may return null. It does so by scanning methods and checking their return statements for potential null values. Apart from the literalreturn nullit will also take methods on collection which are know to be null (based on : error-prone), such asMap.get,Map.put,Queue.poll..etc. Null that are the result oflambda, or streams, are currently ignored.What's your motivation?
To quote this issue #328:
Anything in particular you'd like reviewers to focus on?
This is my first recipe, so I might have formatted make some call, etc.
Anyone you would like to review specifically?
@timtebeek
Checklist