Skip to content
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

Enforce NullAway for Guava packages #1570

Merged
merged 4 commits into from
Sep 15, 2022
Merged

Conversation

schlosna
Copy link
Contributor

@schlosna schlosna commented Sep 15, 2022

Before this PR

NullAway was not checking Guava com.google.common annotated packages. When enabling as a test for palantir/gradle-baseline#2382 it flagged one likely false positive that we can check.

> Task :tritium-processor:compileJava
/home/circleci/project/tritium-processor/src/main/java/com/palantir/tritium/processor/Methods.java:78: error: [NullAway] unboxing of a @Nullable value
                methodFieldName = originalMethodFieldName + i;
                                  ^
    (see http://t.uber.com/nullaway )
1 error

After this PR

==COMMIT_MSG==
Enforce NullAway for Guava packages
==COMMIT_MSG==

Possible downsides?

@changelog-app
Copy link

changelog-app bot commented Sep 15, 2022

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Enforce NullAway for Guava packages

Check the box to generate changelog(s)

  • Generate changelog entry

Comment on lines 69 to 72
String methodName = method.element().getSimpleName().toString();
String originalMethodFieldName = CaseFormat.LOWER_CAMEL
String originalMethodFieldName = Strings.nullToEmpty(CaseFormat.LOWER_CAMEL
.converterTo(CaseFormat.UPPER_UNDERSCORE)
.convert(methodName);
.convert(methodName));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

methodName shouldn't ever be null, so I'm not sure exactly why this flags as possibly null. Going to switch this to a checkNotNull to enforce that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the intent is that convert input is nullable, and the outputs nullability matches the input, but the annotations don't have a clear way to express that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was just a little surprised compiler couldn't verify this was always non-null as it flowed through. There's some interesting bits in Converter and com.google.common.base.NullnessCasts#uncheckedCastNullableTToT

@bulldozer-bot bulldozer-bot bot merged commit 4b8e6e3 into develop Sep 15, 2022
@bulldozer-bot bulldozer-bot bot deleted the ds/guava-nullaway branch September 15, 2022 13:46
@svc-autorelease
Copy link
Collaborator

Released 0.53.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants