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 UNSIGNED_RIGHT_SHIFT. #303

Merged
merged 4 commits into from Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions nullaway/src/main/java/com/uber/nullaway/NullAway.java
Expand Up @@ -1889,6 +1889,7 @@ private boolean mayBeNullExpr(VisitorState state, ExpressionTree expr) {
case XOR:
case LEFT_SHIFT:
case RIGHT_SHIFT:
case UNSIGNED_RIGHT_SHIFT:
// clearly not null
exprMayBeNull = false;
break;
Expand Down
Expand Up @@ -809,4 +809,12 @@ static void testTwoParamIter() {
s.hashCode();
}
}

static int testNoCrashOnShifts(int n) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this really test the relevant code path? I think you need to have some kind of unboxing going on. E.g., make the method return Integer and return an unsigned right shift expression

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The original example is just a shift inside a switch, for an int instance field. But you are right, this test doesn't actually trigger that path. Fixing it now, the new version does fail when I remove the added line in NullAway.java :)

int m = n << 2;
m <<= 2;
n >>= 1;
m >>>= 4;
return (n >>> 3) + m;
}
}