From 637bebd31ca71af20df9521fa7f8f06f24fee2dc Mon Sep 17 00:00:00 2001 From: Nima Karimipour Date: Thu, 16 Nov 2023 16:19:03 -0800 Subject: [PATCH 1/5] add unit test --- .../java/edu/ucr/cs/riple/core/CoreTest.java | 19 +++++++++++++++++++ .../cs/riple/core/tools/CoreTestHelper.java | 5 ++--- .../nullable-multi-modular/build.gradle | 2 ++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/annotator-core/src/test/java/edu/ucr/cs/riple/core/CoreTest.java b/annotator-core/src/test/java/edu/ucr/cs/riple/core/CoreTest.java index 58373c509..3be076e8d 100644 --- a/annotator-core/src/test/java/edu/ucr/cs/riple/core/CoreTest.java +++ b/annotator-core/src/test/java/edu/ucr/cs/riple/core/CoreTest.java @@ -556,4 +556,23 @@ public void nestedParameters() { .toDepth(1) .start(); } + + @Test + public void nonnullTypeUseAcknowledgmentTest(){ + coreTestHelper + .onTarget() + .withSourceLines( + "A.java", + "package test;", + "import org.jetbrains.annotations.NotNull;", + "public class A {", + " private @NotNull Object field;", + "}") + .expectNoReport() + .toDepth(5) + .start(); + // No annotation should be added, since they are annotated as @Nonnull although each can reduce + // the number of errors. + Assert.assertEquals(coreTestHelper.getLog().getInjectedAnnotations().size(), 0); + } } diff --git a/annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/CoreTestHelper.java b/annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/CoreTestHelper.java index 2354764da..d42c9a9a1 100644 --- a/annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/CoreTestHelper.java +++ b/annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/CoreTestHelper.java @@ -402,9 +402,8 @@ public void makeAnnotatorConfigFile(Path configPath) { builder.useCacheImpact = true; builder.sourceTypes.add(SourceType.LOMBOK); builder.cache = true; - builder.useCacheImpact = !getEnvironmentVariable("ANNOTATOR_TEST_DISABLE_CACHING"); - builder.useParallelProcessor = - !getEnvironmentVariable("ANNOTATOR_TEST_DISABLE_PARALLEL_PROCESSING"); + builder.useCacheImpact = false; + builder.useParallelProcessor = true; if (downstreamDependencyAnalysisActivated) { builder.buildCommand = projectBuilder.computeTargetBuildCommandWithLibraryModelLoaderDependency(this.outDirPath); diff --git a/annotator-core/src/test/resources/templates/nullable-multi-modular/build.gradle b/annotator-core/src/test/resources/templates/nullable-multi-modular/build.gradle index c4c50a559..ab8094733 100644 --- a/annotator-core/src/test/resources/templates/nullable-multi-modular/build.gradle +++ b/annotator-core/src/test/resources/templates/nullable-multi-modular/build.gradle @@ -53,6 +53,8 @@ subprojects { // to add @Initializer compileOnly 'com.uber.nullaway:nullaway-annotations:0.10.10' + // to add jetbrains annotations (testing type use vs type declaration) + compileOnly 'org.jetbrains:annotations:24.0.0' compileOnly "org.jspecify:jspecify:0.3.0" compileOnly "com.google.code.findbugs:jsr305:3.0.2" errorprone "com.google.errorprone:error_prone_core:2.3.2" From 8f9f2263322dac0012473d51ddae28a3aca8812d Mon Sep 17 00:00:00 2001 From: nimakarimipour Date: Thu, 16 Nov 2023 17:09:09 -0800 Subject: [PATCH 2/5] update unit test comment --- .../java/edu/ucr/cs/riple/core/CoreTest.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/annotator-core/src/test/java/edu/ucr/cs/riple/core/CoreTest.java b/annotator-core/src/test/java/edu/ucr/cs/riple/core/CoreTest.java index 3be076e8d..d182fbd13 100644 --- a/annotator-core/src/test/java/edu/ucr/cs/riple/core/CoreTest.java +++ b/annotator-core/src/test/java/edu/ucr/cs/riple/core/CoreTest.java @@ -558,21 +558,20 @@ public void nestedParameters() { } @Test - public void nonnullTypeUseAcknowledgmentTest(){ + public void nonnullTypeUseAcknowledgmentTest() { coreTestHelper - .onTarget() - .withSourceLines( - "A.java", - "package test;", - "import org.jetbrains.annotations.NotNull;", - "public class A {", - " private @NotNull Object field;", - "}") - .expectNoReport() - .toDepth(5) - .start(); - // No annotation should be added, since they are annotated as @Nonnull although each can reduce - // the number of errors. + .onTarget() + .withSourceLines( + "A.java", + "package test;", + "import org.jetbrains.annotations.NotNull;", + "public class A {", + " private @NotNull Object field;", + "}") + .expectNoReport() + .toDepth(5) + .start(); + // No annotation should be added even though it can reduce the number of errors. Assert.assertEquals(coreTestHelper.getLog().getInjectedAnnotations().size(), 0); } } From 22c59542d6ce6a1fcbc756d705d43834583e73ba Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Thu, 16 Nov 2023 17:13:00 -0800 Subject: [PATCH 3/5] tweak test to fail --- .../src/test/java/edu/ucr/cs/riple/core/CoreTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/annotator-core/src/test/java/edu/ucr/cs/riple/core/CoreTest.java b/annotator-core/src/test/java/edu/ucr/cs/riple/core/CoreTest.java index d182fbd13..09069add8 100644 --- a/annotator-core/src/test/java/edu/ucr/cs/riple/core/CoreTest.java +++ b/annotator-core/src/test/java/edu/ucr/cs/riple/core/CoreTest.java @@ -566,7 +566,8 @@ public void nonnullTypeUseAcknowledgmentTest() { "package test;", "import org.jetbrains.annotations.NotNull;", "public class A {", - " private @NotNull Object field;", + " static void foo(@NotNull Object o) {}", + " static void bar() { foo(null); }", "}") .expectNoReport() .toDepth(5) From dee745c40e272e1bac2b12ef74e494b1f5a22026 Mon Sep 17 00:00:00 2001 From: nimakarimipour Date: Thu, 16 Nov 2023 18:02:18 -0800 Subject: [PATCH 4/5] fix issue --- .../src/test/java/edu/ucr/cs/riple/core/CoreTest.java | 2 +- .../cs/riple/scanner/location/MethodParameterLocation.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/annotator-core/src/test/java/edu/ucr/cs/riple/core/CoreTest.java b/annotator-core/src/test/java/edu/ucr/cs/riple/core/CoreTest.java index 09069add8..9ce6cc946 100644 --- a/annotator-core/src/test/java/edu/ucr/cs/riple/core/CoreTest.java +++ b/annotator-core/src/test/java/edu/ucr/cs/riple/core/CoreTest.java @@ -558,7 +558,7 @@ public void nestedParameters() { } @Test - public void nonnullTypeUseAcknowledgmentTest() { + public void nonnullTypeUseAnnotationOnFormalParameterAcknowledgmentTest() { coreTestHelper .onTarget() .withSourceLines( diff --git a/annotator-scanner/src/main/java/edu/ucr/cs/riple/scanner/location/MethodParameterLocation.java b/annotator-scanner/src/main/java/edu/ucr/cs/riple/scanner/location/MethodParameterLocation.java index d62d6b8c8..9bc5e9fcf 100644 --- a/annotator-scanner/src/main/java/edu/ucr/cs/riple/scanner/location/MethodParameterLocation.java +++ b/annotator-scanner/src/main/java/edu/ucr/cs/riple/scanner/location/MethodParameterLocation.java @@ -24,6 +24,7 @@ import com.google.common.base.Preconditions; import com.sun.tools.javac.code.Symbol; +import edu.ucr.cs.riple.scanner.Serializer; import javax.lang.model.element.ElementKind; /** @@ -66,8 +67,8 @@ public String tabSeparatedToString() { "\t", type.toString(), enclosingClass.flatName(), - enclosingMethod.toString(), - paramSymbol.toString(), + Serializer.serializeSymbol(enclosingMethod), + Serializer.serializeSymbol(paramSymbol), String.valueOf(index), path != null ? path.toString() : "null"); } From 8d07a4283b6144ceb9a8e7972921f81828a69f20 Mon Sep 17 00:00:00 2001 From: nimakarimipour Date: Thu, 16 Nov 2023 18:08:27 -0800 Subject: [PATCH 5/5] undo unwanted change --- .../java/edu/ucr/cs/riple/core/tools/CoreTestHelper.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/CoreTestHelper.java b/annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/CoreTestHelper.java index d42c9a9a1..2354764da 100644 --- a/annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/CoreTestHelper.java +++ b/annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/CoreTestHelper.java @@ -402,8 +402,9 @@ public void makeAnnotatorConfigFile(Path configPath) { builder.useCacheImpact = true; builder.sourceTypes.add(SourceType.LOMBOK); builder.cache = true; - builder.useCacheImpact = false; - builder.useParallelProcessor = true; + builder.useCacheImpact = !getEnvironmentVariable("ANNOTATOR_TEST_DISABLE_CACHING"); + builder.useParallelProcessor = + !getEnvironmentVariable("ANNOTATOR_TEST_DISABLE_PARALLEL_PROCESSING"); if (downstreamDependencyAnalysisActivated) { builder.buildCommand = projectBuilder.computeTargetBuildCommandWithLibraryModelLoaderDependency(this.outDirPath);