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

Consider adding the uber/NullAway error-prone plugin #273

Open
iamdanfox opened this issue May 4, 2018 · 6 comments
Open

Consider adding the uber/NullAway error-prone plugin #273

iamdanfox opened this issue May 4, 2018 · 6 comments
Labels

Comments

@iamdanfox
Copy link
Contributor

iamdanfox commented May 4, 2018

After removing Findbugs from the tritium repo in palantir/tritium#76, it seems like we might actually now be exposed to a few more bugs.

Apparently https://github.com/uber/NullAway catches silly mistakes like:

static void log(Object x) {
    System.out.println(x.toString());
}
static void foo() {
    log(null);
}

cc @schlosna

Other things worth investigating:

@stale
Copy link

stale bot commented Oct 6, 2018

This issue has been automatically marked as stale because it has not been touched in the last 60 days. Please comment if you'd like to keep it open, otherwise it'll be closed in 7 days time.

@iamdanfox
Copy link
Contributor Author

iamdanfox commented Oct 8, 2018

I've just tried NullAway on a couple of internal repos (template-wc and a larger build-related one) - it was incredibly easy to add and seems to have flagged legitimate cases where the type system cannot prove something won't be null.

    plugins.withId('com.palantir.baseline-error-prone', {
        dependencies {
            compileOnly 'com.google.code.findbugs:jsr305'
            annotationProcessor 'com.uber.nullaway:nullaway'
        }

        tasks.withType(JavaCompile) {
            options.errorprone.errorproneArgs += ['-XepOpt:NullAway:AnnotatedPackages=com.palantir']
        }
    })

I think a remaining question of how we could roll this out everywhere would be how should that AnnotatedPackages=com.palantir thing be specified - in theory we could just bake it into baseline and ask non-palantir users to override it?

There are plenty of ways you can suppress things too if you get annoyed by this plugin (https://github.com/uber/NullAway/wiki/Suppressing-Warnings)

@stale
Copy link

stale bot commented Dec 7, 2018

This issue has been automatically marked as stale because it has not been touched in the last 60 days. Please comment if you'd like to keep it open, otherwise it'll be closed in 7 days time.

@stale stale bot added the stale label Dec 7, 2018
@iamdanfox
Copy link
Contributor Author

Closing out because after trying this on the large build repo, it seemed that readability of map accesses was reduced. Each individual repo is still free to add this snippet and I think we'll continue to experiment with this on certain libraries (e.g. tritium).

@ash211
Copy link
Contributor

ash211 commented Sep 13, 2022

Hi @iamdanfox, enabling this nullaway plugin on an internal repo would have found a bug that hit our users, but sadly it wasn't already enabled. I'd like to revisit turning on findbugs by default, or at least making it an easy opt-in as suggested by @carterkozak

it seemed that readability of map accesses was reduced.

From the above thread it looks like this was the only stated issue with enabling nullaway broadly. Could you please expand on what the problem is with map accesses?

@ash211 ash211 reopened this Sep 13, 2022
@stale stale bot removed the stale label Sep 13, 2022
@iamdanfox
Copy link
Contributor Author

@ash211 here are the illustrative PRs from when I have tried enabling nullaway on large repos:

In both cases, it seemed like there is a very pervasive pattern of having multiple Maps or Sets where there is an invariant that the keysets are exactly equal…. so once you’ve called .get on one, in reality all of the other .get() calls will succeed but static analysis doesn’t know about this invariant... so it forces you to add a bunch of explicit checking.

INTERESTINGLY another repo didn't seem to have this same pattern, so I was able to adopt nullaway without too much friction: https://internal-github/foundry/adjudication-service/pull/2766

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

Successfully merging a pull request may close this issue.

2 participants