Skip to content

Commit f17b330

Browse files
authored
Support primitive static final fields as constant args in access paths (#1105)
1 parent b7dad0c commit f17b330

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

nullaway/src/main/java/com/uber/nullaway/dataflow/AccessPath.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ private AccessPathContext(ImmutableSet<String> immutableTypes) {
742742
}
743743

744744
public boolean isStructurallyImmutableType(Type type) {
745-
return immutableTypes.contains(type.tsym.toString());
745+
return type.isPrimitive() || immutableTypes.contains(type.tsym.toString());
746746
}
747747

748748
public static Builder builder() {

nullaway/src/test/java/com/uber/nullaway/AccessPathsTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,18 @@ public void testVariablesInAccessPathsNegative() {
7979
"import javax.annotation.Nullable;",
8080
"public class Test {",
8181
" private static final int INT_KEY = 42;", // Guaranteed constant!
82+
" // Guaranteed constant after class loading",
83+
" private static final int INT_KEY_HC = \"teststr\".hashCode();",
8284
" public void testEnhancedFor(NullableContainer<String, NullableContainer<Integer, Object>> c) {",
8385
" if (c.get(\"KEY_STR\") != null && c.get(\"KEY_STR\").get(INT_KEY) != null) {",
8486
" c.get(\"KEY_STR\").get(INT_KEY).toString();",
8587
" c.get(\"KEY_STR\").get(Test.INT_KEY).toString();",
8688
" c.get(\"KEY_STR\").get(42).toString();", // Extra magic!
8789
" }",
90+
" if (c.get(\"KEY_STR\") != null && c.get(\"KEY_STR\").get(INT_KEY_HC) != null) {",
91+
" c.get(\"KEY_STR\").get(INT_KEY_HC).toString();",
92+
" c.get(\"KEY_STR\").get(Test.INT_KEY_HC).toString();",
93+
" }",
8894
" }",
8995
"}")
9096
.doTest();

0 commit comments

Comments
 (0)