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

Add support for methods taking literal constant args in Access Paths. #285

Merged
merged 1 commit into from Mar 14, 2019

Conversation

lazaroclapp
Copy link
Collaborator

Consider the code below:

if (x.get(0) != null && x.get(0).foo() != null) {
   return x.get(0).foo().bar(); 
}

This code is safe, but NullAway would miss that before this change, due to get(0) taking an argument. We handle foo() (a zero-arguments method) just fine.

This patch extends our support for method calls with only literal values (and boxed literal values) being passed as arguments. I don't see a case where this would add unsoundness that isn't present on the zero-args case.

@lazaroclapp
Copy link
Collaborator Author

@msridhar Putting this up for review now, but I actually still have to test it internally and profile the change. Since this adds a bunch of steps to AP-construction, it might have a higher performance impact than that we can justify (if that's the case, we can always enable this for selected methods using library models, trading a small amount of manual configuration for faster performance in the common case, but let's first see what the overhead actually is :) )

Copy link
Collaborator

@msridhar msridhar left a comment

Choose a reason for hiding this comment

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

Overall looks good. I do have a slight concern about the perf cost of adding the boxing in AccessPath but we are measuring that.

@lazaroclapp
Copy link
Collaborator Author

No measurable performance impact, and our internal monorepo builds fine with it, so I am merging this :)

@lazaroclapp lazaroclapp merged commit 0b9cdef into master Mar 14, 2019
@lazaroclapp lazaroclapp deleted the lazaro_support_constants_in_aps branch March 14, 2019 03:15
lazaroclapp added a commit that referenced this pull request Oct 14, 2021
This builds upon PR #285 by adding support to code like:

```
if (x.get(ZERO) != null && x.get(ZERO).foo() != null) {
   return x.get(ZERO).foo().bar();
}
```

Where `ZERO` is a compile-time evaluated constant. That is,
a `static final` variable or field of primitive or string type.
lazaroclapp added a commit that referenced this pull request Oct 15, 2021
…504)

This builds upon PR #285 by adding support to code like:

```
if (x.get(ZERO) != null && x.get(ZERO).foo() != null) {
   return x.get(ZERO).foo().bar();
}
```

Where `ZERO` is a compile-time evaluated constant. That is,
a `static final` variable or field of primitive or string type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants