diff --git a/nullaway/src/main/java/com/uber/nullaway/fixserialization/FixSerializationConfig.java b/nullaway/src/main/java/com/uber/nullaway/fixserialization/FixSerializationConfig.java index bbdc0cc6c9..047ac22842 100644 --- a/nullaway/src/main/java/com/uber/nullaway/fixserialization/FixSerializationConfig.java +++ b/nullaway/src/main/java/com/uber/nullaway/fixserialization/FixSerializationConfig.java @@ -59,18 +59,6 @@ public class FixSerializationConfig { */ public final boolean fieldInitInfoEnabled; - /** - * If enabled, the formal parameter at index {@link FixSerializationConfig#paramTestIndex} in all - * methods will be treated as {@code @Nullable} - */ - public final boolean methodParamProtectionTestEnabled; - - /** - * Index of the formal parameter of all methods which will be considered {@code @Nullable}, if - * {@link FixSerializationConfig#methodParamProtectionTestEnabled} is enabled. - */ - public final int paramTestIndex; - /** The directory where all files generated/read by Fix Serialization package resides. */ @Nullable public final String outputDirectory; @@ -83,8 +71,6 @@ public FixSerializationConfig() { suggestEnabled = false; suggestEnclosing = false; fieldInitInfoEnabled = false; - methodParamProtectionTestEnabled = false; - paramTestIndex = Integer.MAX_VALUE; annotationConfig = new AnnotationConfig(); outputDirectory = null; serializer = null; @@ -94,15 +80,11 @@ public FixSerializationConfig( boolean suggestEnabled, boolean suggestEnclosing, boolean fieldInitInfoEnabled, - boolean methodParamProtectionTestEnabled, - int paramTestIndex, AnnotationConfig annotationConfig, String outputDirectory) { this.suggestEnabled = suggestEnabled; this.suggestEnclosing = suggestEnclosing; this.fieldInitInfoEnabled = fieldInitInfoEnabled; - this.methodParamProtectionTestEnabled = methodParamProtectionTestEnabled; - this.paramTestIndex = paramTestIndex; this.outputDirectory = outputDirectory; this.annotationConfig = annotationConfig; serializer = new Serializer(this); @@ -142,12 +124,6 @@ public FixSerializationConfig(String configFilePath) { XMLUtil.getValueFromAttribute( document, "/serialization/fieldInitInfo", "active", Boolean.class) .orElse(false); - methodParamProtectionTestEnabled = - XMLUtil.getValueFromAttribute(document, "/serialization/paramTest", "active", Boolean.class) - .orElse(false); - paramTestIndex = - XMLUtil.getValueFromAttribute(document, "/serialization/paramTest", "index", Integer.class) - .orElse(Integer.MAX_VALUE); String nullableAnnot = XMLUtil.getValueFromTag(document, "/serialization/annotation/nullable", String.class) .orElse("javax.annotation.Nullable"); @@ -169,8 +145,6 @@ public static class Builder { private boolean suggestEnabled; private boolean suggestEnclosing; private boolean fieldInitInfo; - private boolean methodParamProtectionTestEnabled; - private int paramIndex; private String nullable; private String nonnull; @Nullable private String outputDir; @@ -205,12 +179,6 @@ public Builder setOutputDirectory(String outputDir) { return this; } - public Builder setParamProtectionTest(boolean value, int index) { - this.methodParamProtectionTestEnabled = value; - this.paramIndex = index; - return this; - } - /** * Builds and writes the config with the state in builder at the given path as XML. * @@ -229,8 +197,6 @@ public FixSerializationConfig build() { suggestEnabled, suggestEnclosing, fieldInitInfo, - methodParamProtectionTestEnabled, - paramIndex, new AnnotationConfig(nullable, nonnull), outputDir); } diff --git a/nullaway/src/main/java/com/uber/nullaway/fixserialization/XMLUtil.java b/nullaway/src/main/java/com/uber/nullaway/fixserialization/XMLUtil.java index 2a66b17de5..fca8b232fc 100644 --- a/nullaway/src/main/java/com/uber/nullaway/fixserialization/XMLUtil.java +++ b/nullaway/src/main/java/com/uber/nullaway/fixserialization/XMLUtil.java @@ -121,13 +121,6 @@ public static void writeInXMLFormat(FixSerializationConfig config, String path) fieldInitInfoEnabled.setAttribute("active", String.valueOf(config.fieldInitInfoEnabled)); rootElement.appendChild(fieldInitInfoEnabled); - // Method Parameter Protection Test - Element paramTestElement = doc.createElement("paramTest"); - paramTestElement.setAttribute( - "active", String.valueOf(config.methodParamProtectionTestEnabled)); - paramTestElement.setAttribute("index", String.valueOf(config.paramTestIndex)); - rootElement.appendChild(paramTestElement); - // Annotations Element annots = doc.createElement("annotation"); Element nonnull = doc.createElement("nonnull"); diff --git a/nullaway/src/main/java/com/uber/nullaway/handlers/Handlers.java b/nullaway/src/main/java/com/uber/nullaway/handlers/Handlers.java index 90c04c7231..7c8c6272bf 100644 --- a/nullaway/src/main/java/com/uber/nullaway/handlers/Handlers.java +++ b/nullaway/src/main/java/com/uber/nullaway/handlers/Handlers.java @@ -68,10 +68,6 @@ public static Handler buildDefault(Config config) { handlerListBuilder.add( new FieldInitializationSerializationHandler(config.getSerializationConfig())); } - if (config.serializationIsActive() - && config.getSerializationConfig().methodParamProtectionTestEnabled) { - handlerListBuilder.add(new MethodParamNullableInjectorHandler(config)); - } if (config.checkOptionalEmptiness()) { handlerListBuilder.add(new OptionalEmptinessHandler(config, methodNameUtil)); } diff --git a/nullaway/src/main/java/com/uber/nullaway/handlers/MethodParamNullableInjectorHandler.java b/nullaway/src/main/java/com/uber/nullaway/handlers/MethodParamNullableInjectorHandler.java deleted file mode 100644 index f259de5629..0000000000 --- a/nullaway/src/main/java/com/uber/nullaway/handlers/MethodParamNullableInjectorHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2022 Uber Technologies, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package com.uber.nullaway.handlers; - -import com.uber.nullaway.Config; -import com.uber.nullaway.Nullness; -import com.uber.nullaway.dataflow.AccessPath; -import com.uber.nullaway.dataflow.NullnessStore; -import com.uber.nullaway.fixserialization.FixSerializationConfig; -import java.util.List; -import org.checkerframework.nullaway.dataflow.cfg.UnderlyingAST; -import org.checkerframework.nullaway.dataflow.cfg.node.LocalVariableNode; - -/** - * This handler transforms method parameter's state at index {@link - * FixSerializationConfig#paramTestIndex} for all methods to {@code @Nullable}. It provides the - * facility to measure protection of methods against nullability of each argument. This handler is - * activated only if {@link FixSerializationConfig#methodParamProtectionTestEnabled} is enabled. - */ -public class MethodParamNullableInjectorHandler extends BaseNoOpHandler { - - private final FixSerializationConfig config; - - public MethodParamNullableInjectorHandler(Config config) { - this.config = config.getSerializationConfig(); - } - - @Override - public NullnessStore.Builder onDataflowInitialStore( - UnderlyingAST underlyingAST, - List parameters, - NullnessStore.Builder result) { - int index = config.paramTestIndex; - if (index >= parameters.size() || !(underlyingAST instanceof UnderlyingAST.CFGMethod)) { - return super.onDataflowInitialStore(underlyingAST, parameters, result); - } - result.setInformation(AccessPath.fromLocal(parameters.get(index)), Nullness.NULLABLE); - return result; - } -} diff --git a/nullaway/src/test/java/com/uber/nullaway/NullAwaySerializationTest.java b/nullaway/src/test/java/com/uber/nullaway/NullAwaySerializationTest.java index d9f1d03a8d..351a6835f6 100644 --- a/nullaway/src/test/java/com/uber/nullaway/NullAwaySerializationTest.java +++ b/nullaway/src/test/java/com/uber/nullaway/NullAwaySerializationTest.java @@ -681,71 +681,6 @@ public void suggestCustomAnnotTest() { .doTest(); } - @Test - public void examineMethodParamProtectionTest() { - Path tempRoot = Paths.get(temporaryFolder.getRoot().getAbsolutePath(), "custom_annot"); - String output = tempRoot.toString(); - SerializationTestHelper tester = new SerializationTestHelper<>(tempRoot); - try { - Files.createDirectories(tempRoot); - FixSerializationConfig.Builder builder = - new FixSerializationConfig.Builder() - .setSuggest(true, false) - .setParamProtectionTest(true, 0) - .setOutputDirectory(output); - Path config = tempRoot.resolve("serializer.xml"); - Files.createFile(config); - configPath = config.toString(); - builder.writeAsXML(configPath); - } catch (IOException ex) { - throw new UncheckedIOException(ex); - } - tester - .setArgs( - Arrays.asList( - "-d", - temporaryFolder.getRoot().getAbsolutePath(), - "-XepOpt:NullAway:AnnotatedPackages=com.uber", - "-XepOpt:NullAway:SerializeFixMetadata=true", - "-XepOpt:NullAway:FixSerializationConfigPath=" + configPath)) - .addSourceLines( - "com/uber/Test.java", - "package com.uber;", - "public class Test {", - " Object test(Object foo) {", - " // BUG: Diagnostic contains: returning @Nullable", - " return foo;", - " }", - " Object test1(Object foo, Object bar) {", - " // BUG: Diagnostic contains: dereferenced expression foo is @Nullable", - " Integer hash = foo.hashCode();", - " return bar;", - " }", - " void test2(Object f) {", - " // BUG: Diagnostic contains: passing @Nullable", - " test1(f, new Object());", - " }", - "}") - .setExpectedOutputs( - new FixDisplay( - "javax.annotation.Nullable", - "test(java.lang.Object)", - "null", - "METHOD", - "com.uber.Test", - "com/uber/Test.java"), - new FixDisplay( - "javax.annotation.Nullable", - "test1(java.lang.Object,java.lang.Object)", - "foo", - "PARAMETER", - "com.uber.Test", - "com/uber/Test.java")) - .setFactory(fixDisplayFactory) - .setOutputFileNameAndHeader(SUGGEST_FIX_FILE_NAME, SUGGEST_FIX_FILE_HEADER) - .doTest(); - } - @Test public void errorSerializationTest() { SerializationTestHelper tester = new SerializationTestHelper<>(root);