diff --git a/injector/src/main/java/edu/ucr/cs/riple/injector/Helper.java b/injector/src/main/java/edu/ucr/cs/riple/injector/Helper.java index 1424798d1..566a5ced0 100644 --- a/injector/src/main/java/edu/ucr/cs/riple/injector/Helper.java +++ b/injector/src/main/java/edu/ucr/cs/riple/injector/Helper.java @@ -414,21 +414,6 @@ public static Type getTypeFromNode(NodeWithAnnotations node) { return null; } - /** - * Extracts the type of the given node implementing {@link NodeWithAnnotations}. - * - * @param node the node. - * @return the type of the node. - */ - public static Type getType(NodeWithAnnotations node) { - // Currently, we only annotate the element types (contents) of an array, not the pointer - // itself. - // TODO: This should be updated in a follow-up PR. This will reflect both type-use and - // TODO: type-declaration annotations. - Type type = getTypeFromNode(node); - return type instanceof ArrayType ? ((ArrayType) type).getComponentType() : type; - } - /** * Helper method to check if a type is annotated with a specific annotation. * diff --git a/injector/src/main/java/edu/ucr/cs/riple/injector/changes/AddTypeUseMarkerAnnotation.java b/injector/src/main/java/edu/ucr/cs/riple/injector/changes/AddTypeUseMarkerAnnotation.java index b93995717..876962dcf 100644 --- a/injector/src/main/java/edu/ucr/cs/riple/injector/changes/AddTypeUseMarkerAnnotation.java +++ b/injector/src/main/java/edu/ucr/cs/riple/injector/changes/AddTypeUseMarkerAnnotation.java @@ -76,7 +76,7 @@ public Modification computeTextModificationOnType(Type type, AnnotationExpr anno Modification computeTextModificationOnNode(T node, AnnotationExpr annotationExpr) { boolean addOnDeclaration = typeIndex.stream().anyMatch(index -> index.size() == 1 && index.get(0) == 0); - Type type = Helper.getType(node); + Type type = Helper.getTypeFromNode(node); // For annotation on fully qualified name or inner class, the annotation is on the type. (e.g. // Map.@Annot Entry or java.util.@Annot Map) if (addOnDeclaration) { diff --git a/injector/src/main/java/edu/ucr/cs/riple/injector/changes/RemoveTypeUseMarkerAnnotation.java b/injector/src/main/java/edu/ucr/cs/riple/injector/changes/RemoveTypeUseMarkerAnnotation.java index 3bc9dd214..a2c3e66d1 100644 --- a/injector/src/main/java/edu/ucr/cs/riple/injector/changes/RemoveTypeUseMarkerAnnotation.java +++ b/injector/src/main/java/edu/ucr/cs/riple/injector/changes/RemoveTypeUseMarkerAnnotation.java @@ -83,7 +83,7 @@ public Modification computeTextModificationOnType(Type type, AnnotationExpr anno @Override public & NodeWithRange> Modification computeTextModificationOnNode(T node, AnnotationExpr annotationExpr) { - Type type = Helper.getType(node); + Type type = Helper.getTypeFromNode(node); boolean removeOnDeclaration = typeIndex.stream().anyMatch(index -> index.size() == 1 && index.get(0) == 0); diff --git a/injector/src/main/java/edu/ucr/cs/riple/injector/changes/TypeUseAnnotationChange.java b/injector/src/main/java/edu/ucr/cs/riple/injector/changes/TypeUseAnnotationChange.java index a0caa9d4c..a458de6a7 100644 --- a/injector/src/main/java/edu/ucr/cs/riple/injector/changes/TypeUseAnnotationChange.java +++ b/injector/src/main/java/edu/ucr/cs/riple/injector/changes/TypeUseAnnotationChange.java @@ -74,7 +74,7 @@ public abstract Modification computeTextModificationOnType( Modification computeTextModificationOn(T node) { Set modifications = new HashSet<>(); AnnotationExpr annotationExpr = new MarkerAnnotationExpr(annotationName.simpleName); - Type type = Helper.getType(node); + Type type = Helper.getTypeFromNode(node); Modification onNode = computeTextModificationOnNode(node, annotationExpr); if (onNode != null) { modifications.add(onNode); diff --git a/injector/src/test/java/edu/ucr/cs/riple/injector/TypeUseAnnotationTest.java b/injector/src/test/java/edu/ucr/cs/riple/injector/TypeUseAnnotationTest.java index b41b96ed9..3b22ee341 100644 --- a/injector/src/test/java/edu/ucr/cs/riple/injector/TypeUseAnnotationTest.java +++ b/injector/src/test/java/edu/ucr/cs/riple/injector/TypeUseAnnotationTest.java @@ -53,27 +53,29 @@ public void additionTest() { "}") .expectOutput( "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " public void foo() {", - " @UnTainted int f0;", - " @UnTainted Bar<@UnTainted String, Integer, @UnTainted Baz> f1;", - " @UnTainted String f2;", + " @Nullable int f0;", + " @Nullable Bar<@Nullable String, Integer, @Nullable Baz> f1;", + " @Nullable String f2;", " }", "}") .addChanges( new AddTypeUseMarkerAnnotation( - new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f0"), "edu.ucr.UnTainted"), + new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f0"), + "edu.ucr.custom.Nullable"), new AddTypeUseMarkerAnnotation( new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f1"), - "edu.ucr.UnTainted", + "edu.ucr.custom.Nullable", ImmutableList.of( ImmutableList.of(0), ImmutableList.of(1, 0), ImmutableList.of(3, 0), ImmutableList.of(3, 2, 0))), new AddTypeUseMarkerAnnotation( - new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f2"), "edu.ucr.UnTainted")) + new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f2"), + "edu.ucr.custom.Nullable")) .start(); } @@ -83,17 +85,17 @@ public void deletionTest() { .addInput( "Foo.java", "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " public void foo() {", - " @UnTainted int f0;", - " @UnTainted Bar<@UnTainted String, Integer, @UnTainted Baz> f1;", - " @UnTainted String f2;", + " @Nullable int f0;", + " @Nullable Bar<@Nullable String, Integer, @Nullable Baz> f1;", + " @Nullable String f2;", " }", "}") .expectOutput( "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " public void foo() {", " int f0;", @@ -103,17 +105,19 @@ public void deletionTest() { "}") .addChanges( new RemoveTypeUseMarkerAnnotation( - new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f0"), "edu.ucr.UnTainted"), + new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f0"), + "edu.ucr.custom.Nullable"), new RemoveTypeUseMarkerAnnotation( new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f1"), - "edu.ucr.UnTainted", + "edu.ucr.custom.Nullable", ImmutableList.of( ImmutableList.of(0), ImmutableList.of(1, 0), ImmutableList.of(3, 0), ImmutableList.of(3, 2, 0))), new RemoveTypeUseMarkerAnnotation( - new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f2"), "edu.ucr.UnTainted")) + new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f2"), + "edu.ucr.custom.Nullable")) .start(); } @@ -133,32 +137,32 @@ public void additionOnFullyQualifiedTypeNamesTest() { "}") .expectOutput( "package test;", - "import custom.example.Untainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", - " java.lang.@Untainted Object bar;", - " java.util.@Untainted Map f0;", - " java.lang.@Untainted Object baz(java.lang.@Untainted Object param) {;", - " java.lang.@Untainted Object localVar;", + " java.lang.@Nullable Object bar;", + " java.util.@Nullable Map f0;", + " java.lang.@Nullable Object baz(java.lang.@Nullable Object param) {;", + " java.lang.@Nullable Object localVar;", " return new Object();", " }", "}") .addChanges( new AddTypeUseMarkerAnnotation( - new OnField("Foo.java", "test.Foo", Set.of("bar")), "custom.example.Untainted"), + new OnField("Foo.java", "test.Foo", Set.of("bar")), "edu.ucr.custom.Nullable"), new AddTypeUseMarkerAnnotation( new OnField("Foo.java", "test.Foo", Set.of("f0")), - "custom.example.Untainted", + "edu.ucr.custom.Nullable", ImmutableList.of( ImmutableList.of(0), ImmutableList.of(1, 0), ImmutableList.of(2, 0))), new AddTypeUseMarkerAnnotation( new OnMethod("Foo.java", "test.Foo", "baz(java.lang.Object)"), - "custom.example.Untainted"), + "edu.ucr.custom.Nullable"), new AddTypeUseMarkerAnnotation( new OnLocalVariable("Foo.java", "test.Foo", "baz(java.lang.Object)", "localVar"), - "custom.example.Untainted"), + "edu.ucr.custom.Nullable"), new AddTypeUseMarkerAnnotation( new OnParameter("Foo.java", "test.Foo", "baz(java.lang.Object)", 0), - "custom.example.Untainted")) + "edu.ucr.custom.Nullable")) .start(); } @@ -168,18 +172,18 @@ public void deletionOnFullyQualifiedTypeNamesTest() { .addInput( "Foo.java", "package test;", - "import custom.example.Untainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", - " java.lang.@Untainted Object bar;", - " java.util.@Untainted Map f0;", - " java.lang.@Untainted Object baz(java.lang.@Untainted Object param) {;", - " java.lang.@Untainted Object localVar;", + " java.lang.@Nullable Object bar;", + " java.util.@Nullable Map f0;", + " java.lang.@Nullable Object baz(java.lang.@Nullable Object param) {;", + " java.lang.@Nullable Object localVar;", " return new Object();", " }", "}") .expectOutput( "package test;", - "import custom.example.Untainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " java.lang.Object bar;", " java.util.Map f0;", @@ -190,21 +194,21 @@ public void deletionOnFullyQualifiedTypeNamesTest() { "}") .addChanges( new RemoveTypeUseMarkerAnnotation( - new OnField("Foo.java", "test.Foo", Set.of("bar")), "custom.example.Untainted"), + new OnField("Foo.java", "test.Foo", Set.of("bar")), "edu.ucr.custom.Nullable"), new RemoveTypeUseMarkerAnnotation( new OnField("Foo.java", "test.Foo", Set.of("f0")), - "custom.example.Untainted", + "edu.ucr.custom.Nullable", ImmutableList.of( ImmutableList.of(0), ImmutableList.of(1, 0), ImmutableList.of(2, 0))), new RemoveTypeUseMarkerAnnotation( new OnMethod("Foo.java", "test.Foo", "baz(java.lang.Object)"), - "custom.example.Untainted"), + "edu.ucr.custom.Nullable"), new RemoveTypeUseMarkerAnnotation( new OnLocalVariable("Foo.java", "test.Foo", "baz(java.lang.Object)", "localVar"), - "custom.example.Untainted"), + "edu.ucr.custom.Nullable"), new RemoveTypeUseMarkerAnnotation( new OnParameter("Foo.java", "test.Foo", "baz(java.lang.Object)", 0), - "custom.example.Untainted")) + "edu.ucr.custom.Nullable")) .start(); } @@ -223,27 +227,28 @@ public void additionOnArrayTest() { "}") .expectOutput( "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " public void foo() {", - " java.util.@UnTainted Map f0;", - " @UnTainted Map<@UnTainted T, @UnTainted T>[] f1;", - " @UnTainted String[] f2;", + " java.util.@Nullable Map f0;", + " @Nullable Map<@Nullable T, @Nullable T>[] f1;", + " @Nullable String[] f2;", " }", "}") .addChanges( new AddTypeUseMarkerAnnotation( new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f0"), - "edu.ucr.UnTainted", + "edu.ucr.custom.Nullable", ImmutableList.of( ImmutableList.of(0), ImmutableList.of(1, 0), ImmutableList.of(2, 0))), new AddTypeUseMarkerAnnotation( new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f1"), - "edu.ucr.UnTainted", + "edu.ucr.custom.Nullable", ImmutableList.of( ImmutableList.of(0), ImmutableList.of(1, 0), ImmutableList.of(2, 0))), new AddTypeUseMarkerAnnotation( - new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f2"), "edu.ucr.UnTainted")) + new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f2"), + "edu.ucr.custom.Nullable")) .start(); } @@ -253,34 +258,34 @@ public void deletionOnArrayTest() { .addInput( "Foo.java", "package test;", - "import custom.example.Untainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " java.util.Map f0;", - " java.util.@Untainted Map<@Untainted String, @Untainted String[]> f1;", - " @Untainted Map[] f2;", + " java.util.@Nullable Map<@Nullable String, @Nullable String[]> f1;", + " @Nullable Map[] f2;", "}") .expectOutput( "package test;", - "import custom.example.Untainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", - " java.util.@Untainted Map<@Untainted String, @Untainted String[]> f0;", + " java.util.@Nullable Map<@Nullable String, @Nullable String[]> f0;", " java.util.Map f1;", " Map[] f2;", "}") .addChanges( new AddTypeUseMarkerAnnotation( new OnField("Foo.java", "test.Foo", Set.of("f0")), - "custom.example.Untainted", + "edu.ucr.custom.Nullable", ImmutableList.of( ImmutableList.of(0), ImmutableList.of(1, 0), ImmutableList.of(2, 0))), new RemoveTypeUseMarkerAnnotation( new OnField("Foo.java", "test.Foo", Set.of("f1")), - "custom.example.Untainted", + "edu.ucr.custom.Nullable", ImmutableList.of( ImmutableList.of(0), ImmutableList.of(1, 0), ImmutableList.of(2, 0))), new RemoveTypeUseMarkerAnnotation( new OnField("Foo.java", "test.Foo", Set.of("f2")), - "custom.example.Untainted", + "edu.ucr.custom.Nullable", ImmutableList.of( ImmutableList.of(0), ImmutableList.of(1, 0), ImmutableList.of(2, 0)))) .start(); @@ -301,24 +306,26 @@ public void additionOnInitializerTest() { "}") .expectOutput( "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " public void foo() {", - " @UnTainted int f0 = 0;", - " @UnTainted Bar<@UnTainted String, Integer, Baz> f1 = new Bar<@UnTainted String, Integer, Baz>();", - " @UnTainted String f2 = \"FOO\";", + " @Nullable int f0 = 0;", + " @Nullable Bar<@Nullable String, Integer, Baz> f1 = new Bar<@Nullable String, Integer, Baz>();", + " @Nullable String f2 = \"FOO\";", " }", "}") .addChanges( new AddTypeUseMarkerAnnotation( - new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f0"), "edu.ucr.UnTainted"), + new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f0"), + "edu.ucr.custom.Nullable"), new AddTypeUseMarkerAnnotation( new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f1"), - "edu.ucr.UnTainted", + "edu.ucr.custom.Nullable", ImmutableList.of( ImmutableList.of(0), ImmutableList.of(1, 0), ImmutableList.of(3, 2, 0))), new AddTypeUseMarkerAnnotation( - new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f2"), "edu.ucr.UnTainted")) + new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f2"), + "edu.ucr.custom.Nullable")) .start(); } @@ -328,35 +335,38 @@ public void removalOnDeclarationOnly() { .addInput( "Foo.java", "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " public void foo() {", - " @UnTainted int f0 = 0;", - " @UnTainted Bar<@UnTainted String, @UnTainted Integer, @UnTainted Baz<@UnTainted String, @UnTainted Integer>> f1 = new Custom<@UnTainted String, @UnTainted String>();", - " @UnTainted String f2 = \"FOO\";", + " @Nullable int f0 = 0;", + " @Nullable Bar<@Nullable String, @Nullable Integer, @Nullable Baz<@Nullable String, @Nullable Integer>> f1 = new Custom<@Nullable String, @Nullable String>();", + " @Nullable String f2 = \"FOO\";", " }", "}") .expectOutput( "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " public void foo() {", " int f0 = 0;", - " Bar<@UnTainted String, @UnTainted Integer, @UnTainted Baz<@UnTainted String, @UnTainted Integer>> f1 = new Custom<@UnTainted String, @UnTainted String>();", + " Bar<@Nullable String, @Nullable Integer, @Nullable Baz<@Nullable String, @Nullable Integer>> f1 = new Custom<@Nullable String, @Nullable String>();", " String f2 = \"FOO\";", " }", "}") .addChanges( new AddTypeUseMarkerAnnotation( - new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f0"), "edu.ucr.UnTainted") + new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f0"), + "edu.ucr.custom.Nullable") .toDeclaration() .getReverse(), new AddTypeUseMarkerAnnotation( - new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f1"), "edu.ucr.UnTainted") + new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f1"), + "edu.ucr.custom.Nullable") .toDeclaration() .getReverse(), new AddTypeUseMarkerAnnotation( - new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f2"), "edu.ucr.UnTainted") + new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f2"), + "edu.ucr.custom.Nullable") .toDeclaration() .getReverse()) .start(); @@ -393,18 +403,18 @@ public void deletionOnInitializerTest() { .addInput( "Foo.java", "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " public void foo() {", - " @UnTainted int f0 = 0;", - " @UnTainted Bar<@UnTainted String, @UnTainted Integer, @UnTainted Baz<@UnTainted String, @UnTainted Integer>> f1 = new Bar<@UnTainted String, @UnTainted Integer, @UnTainted Baz<@UnTainted String, @UnTainted Integer>>();", - " @UnTainted String f2 = \"FOO\";", - " @UnTainted Bar<@UnTainted String, @UnTainted Integer[], @UnTainted Baz<@UnTainted String, @UnTainted Integer>> f3 = new Bar<@UnTainted String, @UnTainted Integer[], @UnTainted Baz<@UnTainted String, @UnTainted Integer>>();", + " @Nullable int f0 = 0;", + " @Nullable Bar<@Nullable String, @Nullable Integer, @Nullable Baz<@Nullable String, @Nullable Integer>> f1 = new Bar<@Nullable String, @Nullable Integer, @Nullable Baz<@Nullable String, @Nullable Integer>>();", + " @Nullable String f2 = \"FOO\";", + " @Nullable Bar<@Nullable String, @Nullable Integer[], @Nullable Baz<@Nullable String, @Nullable Integer>> f3 = new Bar<@Nullable String, @Nullable Integer[], @Nullable Baz<@Nullable String, @Nullable Integer>>();", " }", "}") .expectOutput( "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " public void foo() {", " int f0 = 0;", @@ -415,10 +425,11 @@ public void deletionOnInitializerTest() { "}") .addChanges( new RemoveTypeUseMarkerAnnotation( - new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f0"), "edu.ucr.UnTainted"), + new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f0"), + "edu.ucr.custom.Nullable"), new RemoveTypeUseMarkerAnnotation( new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f1"), - "edu.ucr.UnTainted", + "edu.ucr.custom.Nullable", ImmutableList.of( ImmutableList.of(0), ImmutableList.of(1, 0), @@ -427,10 +438,11 @@ public void deletionOnInitializerTest() { ImmutableList.of(3, 1, 0), ImmutableList.of(3, 2, 0))), new RemoveTypeUseMarkerAnnotation( - new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f2"), "edu.ucr.UnTainted"), + new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f2"), + "edu.ucr.custom.Nullable"), new RemoveTypeUseMarkerAnnotation( new OnLocalVariable("Foo.java", "test.Foo", "foo()", "f3"), - "edu.ucr.UnTainted", + "edu.ucr.custom.Nullable", ImmutableList.of( ImmutableList.of(0), ImmutableList.of(1, 0), @@ -447,10 +459,10 @@ public void avoidDuplicateOnAnnotationOnInnerClass() { .addInput( "Foo.java", "package test;", - "import edu.ucr.Untainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " public void foo() {", - " for (Map.@Untainted Entry<@Untainted String, @Untainted String> entry : m_additionalPreferences.entrySet()) {", + " for (Map.@Nullable Entry<@Nullable String, @Nullable String> entry : m_additionalPreferences.entrySet()) {", " String key = entry.getKey();", " @RUntainted String value = entry.getValue();", " m_user.setAdditionalInfo(PREFERENCES_ADDITIONAL_PREFIX + key, value);", @@ -459,10 +471,10 @@ public void avoidDuplicateOnAnnotationOnInnerClass() { "}") .expectOutput( "package test;", - "import edu.ucr.Untainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " public void foo() {", - " for (Map.@Untainted Entry<@Untainted String, @Untainted String> entry : m_additionalPreferences.entrySet()) {", + " for (Map.@Nullable Entry<@Nullable String, @Nullable String> entry : m_additionalPreferences.entrySet()) {", " String key = entry.getKey();", " @RUntainted String value = entry.getValue();", " m_user.setAdditionalInfo(PREFERENCES_ADDITIONAL_PREFIX + key, value);", @@ -471,7 +483,8 @@ public void avoidDuplicateOnAnnotationOnInnerClass() { "}") .addChanges( new AddTypeUseMarkerAnnotation( - new OnLocalVariable("Foo.java", "test.Foo", "foo()", "entry"), "edu.ucr.Untainted")) + new OnLocalVariable("Foo.java", "test.Foo", "foo()", "entry"), + "edu.ucr.custom.Nullable")) .start(); } @@ -481,25 +494,25 @@ public void addTypeUseOnType() { .addInput( "Foo.java", "package test;", - "import edu.ucr.Untainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " private final Object f0;", " private final Object f1;", "}") .expectOutput( "package test;", - "import edu.ucr.Untainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", - " @Untainted private final Object f0;", - " private final @Untainted Object f1;", + " @Nullable private final Object f0;", + " private final @Nullable Object f1;", "}") .addChanges( new AddMarkerAnnotation( new OnField("Foo.java", "test.Foo", Collections.singleton("f0")), - "edu.ucr.Untainted"), + "edu.ucr.custom.Nullable"), new AddTypeUseMarkerAnnotation( new OnField("Foo.java", "test.Foo", Collections.singleton("f1")), - "edu.ucr.Untainted")) + "edu.ucr.custom.Nullable")) .start(); } @@ -516,20 +529,20 @@ public void additionOnFullyQualifiedTypeNamesOnTypeArgsTest() { "}") .expectOutput( "package test;", - "import custom.example.Untainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " void baz(java.lang.Object param) {", - " final java.util.HashMap localVar = new HashMap<@Untainted String, @Untainted String>();", + " final java.util.HashMap localVar = new HashMap<@Nullable String, @Nullable String>();", " }", "}") .addChanges( new AddTypeUseMarkerAnnotation( new OnLocalVariable("Foo.java", "test.Foo", "baz(java.lang.Object)", "localVar"), - "custom.example.Untainted", + "edu.ucr.custom.Nullable", ImmutableList.of(ImmutableList.of(1, 0))), new AddTypeUseMarkerAnnotation( new OnLocalVariable("Foo.java", "test.Foo", "baz(java.lang.Object)", "localVar"), - "custom.example.Untainted", + "edu.ucr.custom.Nullable", ImmutableList.of(ImmutableList.of(2, 0)))) .start(); } @@ -540,15 +553,15 @@ public void deletionOnFullyQualifiedTypeNamesOnTypeArgsTest() { .addInput( "Foo.java", "package test;", - "import custom.example.Untainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " void baz(java.lang.Object param) {", - " final java.util.HashMap localVar = new HashMap<@Untainted String, @Untainted String>();", + " final java.util.HashMap localVar = new HashMap<@Nullable String, @Nullable String>();", " }", "}") .expectOutput( "package test;", - "import custom.example.Untainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " void baz(java.lang.Object param) {", " final java.util.HashMap localVar = new HashMap();", @@ -557,78 +570,15 @@ public void deletionOnFullyQualifiedTypeNamesOnTypeArgsTest() { .addChanges( new RemoveTypeUseMarkerAnnotation( new OnLocalVariable("Foo.java", "test.Foo", "baz(java.lang.Object)", "localVar"), - "custom.example.Untainted", + "edu.ucr.custom.Nullable", ImmutableList.of(ImmutableList.of(1, 0))), new RemoveTypeUseMarkerAnnotation( new OnLocalVariable("Foo.java", "test.Foo", "baz(java.lang.Object)", "localVar"), - "custom.example.Untainted", + "edu.ucr.custom.Nullable", ImmutableList.of(ImmutableList.of(2, 0)))) .start(); } - @Test - public void onArrayTypeDuplicateTest() { - injectorTestHelper - .addInput( - "Foo.java", - "package test;", - "import custom.example.Untainted;", - "public class Foo {", - " void baz(java.lang.Object param) {", - " final java.lang.@RUntainted String[] localVar = content.split(\"\\n\");", - " }", - "}") - .expectOutput( - "package test;", - "import custom.example.Untainted;", - "public class Foo {", - " void baz(java.lang.Object param) {", - " final java.lang.@RUntainted String[] localVar = content.split(\"\\n\");", - " }", - "}") - .addChanges( - new AddTypeUseMarkerAnnotation( - new OnLocalVariable("Foo.java", "test.Foo", "baz(java.lang.Object)", "localVar"), - "custom.example.RUntainted"), - new AddTypeUseMarkerAnnotation( - new OnLocalVariable("Foo.java", "test.Foo", "baz(java.lang.Object)", "localVar"), - "custom.example.RUntainted"), - new AddTypeUseMarkerAnnotation( - new OnLocalVariable("Foo.java", "test.Foo", "baz(java.lang.Object)", "localVar"), - "custom.example.RUntainted"), - new AddTypeUseMarkerAnnotation( - new OnLocalVariable("Foo.java", "test.Foo", "baz(java.lang.Object)", "localVar"), - "custom.example.RUntainted")) - .start(); - } - - @Test - public void onArrayTypeDeletionTest() { - injectorTestHelper - .addInput( - "Foo.java", - "package test;", - "import custom.example.Untainted;", - "public class Foo {", - " void baz(java.lang.Object param) {", - " final java.lang.@RUntainted String[] localVar = content.split(\"\\n\");", - " }", - "}") - .expectOutput( - "package test;", - "import custom.example.Untainted;", - "public class Foo {", - " void baz(java.lang.Object param) {", - " final java.lang.String[] localVar = content.split(\"\\n\");", - " }", - "}") - .addChanges( - new RemoveTypeUseMarkerAnnotation( - new OnLocalVariable("Foo.java", "test.Foo", "baz(java.lang.Object)", "localVar"), - "custom.example.RUntainted")) - .start(); - } - @Test public void additionOnInitializerFieldTest() { injectorTestHelper @@ -640,14 +590,14 @@ public void additionOnInitializerFieldTest() { "}") .expectOutput( "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", - " Map map = new HashMap();", + " Map map = new HashMap();", "}") .addChanges( new AddTypeUseMarkerAnnotation( new OnField("Foo.java", "test.Foo", Collections.singleton("map")), - "edu.ucr.UnTainted", + "edu.ucr.custom.Nullable", ImmutableList.of(ImmutableList.of(2, 0)))) .start(); } @@ -658,20 +608,20 @@ public void deletionOnInitializerFieldTest() { .addInput( "Foo.java", "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", - " Map map = new HashMap();", + " Map map = new HashMap();", "}") .expectOutput( "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " Map map = new HashMap();", "}") .addChanges( new RemoveTypeUseMarkerAnnotation( new OnField("Foo.java", "test.Foo", Collections.singleton("map")), - "edu.ucr.UnTainted", + "edu.ucr.custom.Nullable", ImmutableList.of(ImmutableList.of(2, 0)))) .start(); } @@ -682,14 +632,14 @@ public void additionOnWildCard() { .addInput("Foo.java", "package test;", "public class Foo {", " Map map;", "}") .expectOutput( "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", - " Map map;", + " Map map;", "}") .addChanges( new AddTypeUseMarkerAnnotation( new OnField("Foo.java", "test.Foo", Collections.singleton("map")), - "edu.ucr.UnTainted", + "edu.ucr.custom.Nullable", ImmutableList.of(ImmutableList.of(2, 0)))) .start(); } @@ -700,20 +650,20 @@ public void deletionOnWildCard() { .addInput( "Foo.java", "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", - " Map map;", + " Map map;", "}") .expectOutput( "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " Map map;", "}") .addChanges( new RemoveTypeUseMarkerAnnotation( new OnField("Foo.java", "test.Foo", Collections.singleton("map")), - "edu.ucr.UnTainted", + "edu.ucr.custom.Nullable", ImmutableList.of(ImmutableList.of(2, 0)))) .start(); } @@ -724,20 +674,20 @@ public void wildCardExtendedType() { .addInput( "Foo.java", "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " public synchronized ConfigurationBuilder> m() throws ConfigurationException {}", "}") .expectOutput( "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", - " public synchronized ConfigurationBuilder> m() throws ConfigurationException {}", + " public synchronized ConfigurationBuilder> m() throws ConfigurationException {}", "}") .addChanges( new AddTypeUseMarkerAnnotation( new OnMethod("Foo.java", "test.Foo", "m()"), - "edu.ucr.UnTainted", + "edu.ucr.custom.Nullable", ImmutableList.of(ImmutableList.of(1, 0)))) .start(); } @@ -748,20 +698,20 @@ public void existingWildCardExtendedType() { .addInput( "Foo.java", "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", - " public synchronized ConfigurationBuilder> m() throws ConfigurationException {}", + " public synchronized ConfigurationBuilder> m() throws ConfigurationException {}", "}") .expectOutput( "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", - " public synchronized ConfigurationBuilder> m() throws ConfigurationException {}", + " public synchronized ConfigurationBuilder> m() throws ConfigurationException {}", "}") .addChanges( new AddTypeUseMarkerAnnotation( new OnMethod("Foo.java", "test.Foo", "m()"), - "edu.ucr.UnTainted", + "edu.ucr.custom.Nullable", ImmutableList.of(ImmutableList.of(1, 0)))) .start(); } @@ -772,20 +722,20 @@ public void removeWildCardExtendedType() { .addInput( "Foo.java", "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", - " public synchronized ConfigurationBuilder> m() throws ConfigurationException {}", + " public synchronized ConfigurationBuilder> m() throws ConfigurationException {}", "}") .expectOutput( "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " public synchronized ConfigurationBuilder> m() throws ConfigurationException {}", "}") .addChanges( new RemoveTypeUseMarkerAnnotation( new OnMethod("Foo.java", "test.Foo", "m()"), - "edu.ucr.UnTainted", + "edu.ucr.custom.Nullable", ImmutableList.of(ImmutableList.of(1, 0)))) .start(); } @@ -796,7 +746,7 @@ public void multipleInlineLocalVariableTest() { .addInput( "Foo.java", "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " public void bar() {", " List a1 = null, a2 = null;", @@ -804,24 +754,24 @@ public void multipleInlineLocalVariableTest() { "}") .expectOutput( "package test;", - "import edu.ucr.UnTainted;", + "import edu.ucr.custom.Nullable;", "public class Foo {", " public void bar() {", - " @UnTainted List<@UnTainted Node> a1 = null, a2 = null;", + " @Nullable List<@Nullable Node> a1 = null, a2 = null;", " }", "}") .addChanges( new AddTypeUseMarkerAnnotation( new OnLocalVariable("Foo.java", "test.Foo", "bar()", "a1"), - "edu.ucr.UnTainted", + "edu.ucr.custom.Nullable", ImmutableList.of(ImmutableList.of(0))), new AddTypeUseMarkerAnnotation( new OnLocalVariable("Foo.java", "test.Foo", "bar()", "a1"), - "edu.ucr.UnTainted", + "edu.ucr.custom.Nullable", ImmutableList.of(ImmutableList.of(1, 0))), new AddTypeUseMarkerAnnotation( new OnLocalVariable("Foo.java", "test.Foo", "bar()", "a2"), - "edu.ucr.UnTainted", + "edu.ucr.custom.Nullable", ImmutableList.of(ImmutableList.of(1, 0)))) .start(); }