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

Support local variable arrays #270

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion annotator-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ spotless {
}

// Should be the latest supporting version of NullAway.
def NULLAWAY_TEST = "0.12.3"
def NULLAWAY_TEST = "0.12.4"

tasks.test.dependsOn(':annotator-scanner:publishToMavenLocal')

Expand Down
25 changes: 25 additions & 0 deletions annotator-core/src/test/java/edu/ucr/cs/riple/core/CoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.common.collect.ImmutableList;
import edu.ucr.cs.riple.core.tools.TReport;
import edu.ucr.cs.riple.injector.location.OnField;
import edu.ucr.cs.riple.injector.location.OnLocalVariable;
import edu.ucr.cs.riple.injector.location.OnMethod;
import edu.ucr.cs.riple.injector.location.OnParameter;
import java.util.Collections;
Expand Down Expand Up @@ -597,4 +598,28 @@ public void assignNullableToNonnullArrayComponentTypeTest() {
.enableJSpecifyMode()
.start();
}

@Test
public void assignNullableToNonnullArrayComponentTypeLocalVariableTest() {
coreTestHelper
.onTarget()
.withSourceLines(
"Main.java",
"package test;",
"public class Main {",
" void run() {",
" Object[] arr = new Object[1];",
" arr[0] = null;",
" }",
"}")
.withExpectedReports(
new TReport(
new OnLocalVariable("Main.java", "test.Main", "run()", "arr"),
ImmutableList.of(ImmutableList.of(1, 0)),
-1))
.disableBailOut()
.checkExpectedOutput("assignNullableToNonnullArrayComponentTypeLocalVariableTest/expected")
.enableJSpecifyMode()
.start();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package test;
import org.jspecify.annotations.Nullable;
public class Main {
void run() {
@Nullable Object[] arr = new Object[1];
arr[0] = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public static Location createLocationFromArrayInfo(String[] values) {
return new OnMethod(path, clazz, values[2]);
case PARAMETER:
return new OnParameter(path, clazz, values[2], Integer.parseInt(values[4]));
case LOCAL_VARIABLE:
return new OnLocalVariable(path, clazz, values[2], values[3]);
default:
throw new RuntimeException(
"Cannot reach this statement, values: " + Arrays.toString(values));
Expand Down
Loading