From 2198833ab4b16b41c841756b3e2d5623502f310c Mon Sep 17 00:00:00 2001 From: Nima Karimipour Date: Thu, 14 Jul 2022 12:59:47 -0700 Subject: [PATCH] Remove nullable annotation configuration in fix serialization. (#621) Following GH-517 If `serializeFixMetadata` is active, `NullAway` will serialize suggested type changes (currently just adding `@Nullable`). In the `FixSerializationConfig` file we can set a custom annotation that `NullAway` will use in the output serializations. However, this process can be simplified by just asking `NullAway` to serialize type change locations with a default annotation name, any tool processing this output can use their own preferred annotation. After this PR the following entity will be removed from the config `.xml` file: ```xml ... ... SuggestedNullableFixInfo.java} | 34 ++--- .../qual/AnnotationConfig.java | 82 ------------ .../nullaway/NullAwaySerializationTest.java | 123 +++--------------- 7 files changed, 58 insertions(+), 273 deletions(-) rename nullaway/src/main/java/com/uber/nullaway/fixserialization/out/{SuggestedFixInfo.java => SuggestedNullableFixInfo.java} (76%) delete mode 100644 nullaway/src/main/java/com/uber/nullaway/fixserialization/qual/AnnotationConfig.java 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 047ac22842..45e8bf8853 100644 --- a/nullaway/src/main/java/com/uber/nullaway/fixserialization/FixSerializationConfig.java +++ b/nullaway/src/main/java/com/uber/nullaway/fixserialization/FixSerializationConfig.java @@ -23,7 +23,7 @@ package com.uber.nullaway.fixserialization; import com.google.common.base.Preconditions; -import com.uber.nullaway.fixserialization.qual.AnnotationConfig; +import com.uber.nullaway.fixserialization.out.SuggestedNullableFixInfo; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; @@ -41,9 +41,9 @@ public class FixSerializationConfig { * If enabled, the corresponding output file will be cleared and for all reported errors, NullAway * will serialize information and suggest type changes to resolve them, in case these errors could * be fixed by adding a {@code @Nullable} annotation. These type change suggestions are in form of - * {@link com.uber.nullaway.fixserialization.out.SuggestedFixInfo} instances and will be - * serialized at output directory. If deactivated, no {@code SuggestedFixInfo} will be created and - * the output file will remain untouched. + * {@link SuggestedNullableFixInfo} instances and will be serialized at output directory. If + * deactivated, no {@code SuggestedFixInfo} will be created and the output file will remain + * untouched. */ public final boolean suggestEnabled; /** @@ -62,8 +62,6 @@ public class FixSerializationConfig { /** The directory where all files generated/read by Fix Serialization package resides. */ @Nullable public final String outputDirectory; - public final AnnotationConfig annotationConfig; - @Nullable private final Serializer serializer; /** Default Constructor, all features are disabled with this config. */ @@ -71,7 +69,6 @@ public FixSerializationConfig() { suggestEnabled = false; suggestEnclosing = false; fieldInitInfoEnabled = false; - annotationConfig = new AnnotationConfig(); outputDirectory = null; serializer = null; } @@ -80,13 +77,11 @@ public FixSerializationConfig( boolean suggestEnabled, boolean suggestEnclosing, boolean fieldInitInfoEnabled, - AnnotationConfig annotationConfig, - String outputDirectory) { + @Nullable String outputDirectory) { this.suggestEnabled = suggestEnabled; this.suggestEnclosing = suggestEnclosing; this.fieldInitInfoEnabled = fieldInitInfoEnabled; this.outputDirectory = outputDirectory; - this.annotationConfig = annotationConfig; serializer = new Serializer(this); } @@ -124,13 +119,6 @@ public FixSerializationConfig(String configFilePath) { XMLUtil.getValueFromAttribute( document, "/serialization/fieldInitInfo", "active", Boolean.class) .orElse(false); - String nullableAnnot = - XMLUtil.getValueFromTag(document, "/serialization/annotation/nullable", String.class) - .orElse("javax.annotation.Nullable"); - String nonnullAnnot = - XMLUtil.getValueFromTag(document, "/serialization/annotation/nonnull", String.class) - .orElse("javax.annotation.Nonnull"); - this.annotationConfig = new AnnotationConfig(nullableAnnot, nonnullAnnot); serializer = new Serializer(this); } @@ -145,16 +133,12 @@ public static class Builder { private boolean suggestEnabled; private boolean suggestEnclosing; private boolean fieldInitInfo; - private String nullable; - private String nonnull; @Nullable private String outputDir; public Builder() { suggestEnabled = false; suggestEnclosing = false; fieldInitInfo = false; - nullable = "javax.annotation.Nullable"; - nonnull = "javax.annotation.Nonnull"; } public Builder setSuggest(boolean value, boolean withEnclosing) { @@ -163,12 +147,6 @@ public Builder setSuggest(boolean value, boolean withEnclosing) { return this; } - public Builder setAnnotations(String nullable, String nonnull) { - this.nullable = nullable; - this.nonnull = nonnull; - return this; - } - public Builder setFieldInitInfo(boolean enabled) { this.fieldInitInfo = enabled; return this; @@ -193,12 +171,7 @@ public FixSerializationConfig build() { if (outputDir == null) { throw new IllegalStateException("did not set mandatory output directory"); } - return new FixSerializationConfig( - suggestEnabled, - suggestEnclosing, - fieldInitInfo, - new AnnotationConfig(nullable, nonnull), - outputDir); + return new FixSerializationConfig(suggestEnabled, suggestEnclosing, fieldInitInfo, outputDir); } } } diff --git a/nullaway/src/main/java/com/uber/nullaway/fixserialization/SerializationService.java b/nullaway/src/main/java/com/uber/nullaway/fixserialization/SerializationService.java index 7146f2d1a2..0e3ea9c164 100644 --- a/nullaway/src/main/java/com/uber/nullaway/fixserialization/SerializationService.java +++ b/nullaway/src/main/java/com/uber/nullaway/fixserialization/SerializationService.java @@ -33,7 +33,7 @@ import com.uber.nullaway.Nullness; import com.uber.nullaway.fixserialization.location.FixLocation; import com.uber.nullaway.fixserialization.out.ErrorInfo; -import com.uber.nullaway.fixserialization.out.SuggestedFixInfo; +import com.uber.nullaway.fixserialization.out.SuggestedNullableFixInfo; /** A facade class to interact with fix serialization package. */ public class SerializationService { @@ -65,12 +65,13 @@ public static void serializeFixSuggestion( return; } FixLocation location = FixLocation.createFixLocationFromSymbol(target); - SuggestedFixInfo suggestedFixInfo = - buildFixMetadata(config, state.getPath(), errorMessage, location); + SuggestedNullableFixInfo suggestedNullableFixInfo = + buildFixMetadata(state.getPath(), errorMessage, location); Serializer serializer = serializationConfig.getSerializer(); Preconditions.checkNotNull( serializer, "Serializer shouldn't be null at this point, error in configuration setting!"); - serializer.serializeSuggestedFixInfo(suggestedFixInfo, serializationConfig.suggestEnclosing); + serializer.serializeSuggestedFixInfo( + suggestedNullableFixInfo, serializationConfig.suggestEnclosing); } /** @@ -88,10 +89,12 @@ public static void serializeReportingError( serializer.serializeErrorInfo(new ErrorInfo(state.getPath(), errorMessage)); } - /** Builds the {@link SuggestedFixInfo} instance based on the {@link ErrorMessage} type. */ - private static SuggestedFixInfo buildFixMetadata( - Config config, TreePath path, ErrorMessage errorMessage, FixLocation location) { - SuggestedFixInfo suggestedFixInfo; + /** + * Builds the {@link SuggestedNullableFixInfo} instance based on the {@link ErrorMessage} type. + */ + private static SuggestedNullableFixInfo buildFixMetadata( + TreePath path, ErrorMessage errorMessage, FixLocation location) { + SuggestedNullableFixInfo suggestedNullableFixInfo; switch (errorMessage.getMessageType()) { case RETURN_NULLABLE: case WRONG_OVERRIDE_RETURN: @@ -100,17 +103,12 @@ private static SuggestedFixInfo buildFixMetadata( case FIELD_NO_INIT: case ASSIGN_FIELD_NULLABLE: case METHOD_NO_INIT: - suggestedFixInfo = - new SuggestedFixInfo( - path, - location, - errorMessage, - config.getSerializationConfig().annotationConfig.getNullable()); + suggestedNullableFixInfo = new SuggestedNullableFixInfo(path, location, errorMessage); break; default: throw new IllegalStateException( "Cannot suggest a type to resolve error of type: " + errorMessage.getMessageType()); } - return suggestedFixInfo; + return suggestedNullableFixInfo; } } diff --git a/nullaway/src/main/java/com/uber/nullaway/fixserialization/Serializer.java b/nullaway/src/main/java/com/uber/nullaway/fixserialization/Serializer.java index 614f746968..a63cee033b 100644 --- a/nullaway/src/main/java/com/uber/nullaway/fixserialization/Serializer.java +++ b/nullaway/src/main/java/com/uber/nullaway/fixserialization/Serializer.java @@ -25,7 +25,7 @@ import com.uber.nullaway.ErrorMessage; import com.uber.nullaway.fixserialization.out.ErrorInfo; import com.uber.nullaway.fixserialization.out.FieldInitializationInfo; -import com.uber.nullaway.fixserialization.out.SuggestedFixInfo; +import com.uber.nullaway.fixserialization.out.SuggestedNullableFixInfo; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -55,16 +55,17 @@ public Serializer(FixSerializationConfig config) { } /** - * Appends the string representation of the {@link SuggestedFixInfo}. + * Appends the string representation of the {@link SuggestedNullableFixInfo}. * - * @param suggestedFixInfo SuggestedFixInfo object. + * @param suggestedNullableFixInfo SuggestedFixInfo object. * @param enclosing Flag to control if enclosing method and class should be included. */ - public void serializeSuggestedFixInfo(SuggestedFixInfo suggestedFixInfo, boolean enclosing) { + public void serializeSuggestedFixInfo( + SuggestedNullableFixInfo suggestedNullableFixInfo, boolean enclosing) { if (enclosing) { - suggestedFixInfo.initEnclosing(); + suggestedNullableFixInfo.initEnclosing(); } - appendToFile(suggestedFixInfo.tabSeparatedToString(), suggestedFixesOutputPath); + appendToFile(suggestedNullableFixInfo.tabSeparatedToString(), suggestedFixesOutputPath); } /** @@ -102,7 +103,7 @@ private void initializeOutputFiles(FixSerializationConfig config) { try { Files.createDirectories(Paths.get(config.outputDirectory)); if (config.suggestEnabled) { - initializeFile(suggestedFixesOutputPath, SuggestedFixInfo.header()); + initializeFile(suggestedFixesOutputPath, SuggestedNullableFixInfo.header()); } if (config.fieldInitInfoEnabled) { initializeFile(fieldInitializationOutputPath, FieldInitializationInfo.header()); 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 fca8b232fc..b39b488936 100644 --- a/nullaway/src/main/java/com/uber/nullaway/fixserialization/XMLUtil.java +++ b/nullaway/src/main/java/com/uber/nullaway/fixserialization/XMLUtil.java @@ -121,16 +121,6 @@ public static void writeInXMLFormat(FixSerializationConfig config, String path) fieldInitInfoEnabled.setAttribute("active", String.valueOf(config.fieldInitInfoEnabled)); rootElement.appendChild(fieldInitInfoEnabled); - // Annotations - Element annots = doc.createElement("annotation"); - Element nonnull = doc.createElement("nonnull"); - nonnull.setTextContent(config.annotationConfig.getNonNull().getFullName()); - Element nullable = doc.createElement("nullable"); - nullable.setTextContent(config.annotationConfig.getNullable().getFullName()); - annots.appendChild(nullable); - annots.appendChild(nonnull); - rootElement.appendChild(annots); - // Output dir Element outputDir = doc.createElement("path"); outputDir.setTextContent(config.outputDirectory); diff --git a/nullaway/src/main/java/com/uber/nullaway/fixserialization/out/SuggestedFixInfo.java b/nullaway/src/main/java/com/uber/nullaway/fixserialization/out/SuggestedNullableFixInfo.java similarity index 76% rename from nullaway/src/main/java/com/uber/nullaway/fixserialization/out/SuggestedFixInfo.java rename to nullaway/src/main/java/com/uber/nullaway/fixserialization/out/SuggestedNullableFixInfo.java index 7cb60ec6cb..493ca8c709 100644 --- a/nullaway/src/main/java/com/uber/nullaway/fixserialization/out/SuggestedFixInfo.java +++ b/nullaway/src/main/java/com/uber/nullaway/fixserialization/out/SuggestedNullableFixInfo.java @@ -26,30 +26,23 @@ import com.sun.source.util.TreePath; import com.uber.nullaway.ErrorMessage; import com.uber.nullaway.fixserialization.location.FixLocation; -import com.uber.nullaway.fixserialization.qual.AnnotationConfig; import java.util.Objects; -/** Stores information suggesting a type change of an element in source code. */ -public class SuggestedFixInfo { +/** Stores information suggesting adding @Nullable on an element in source code. */ +public class SuggestedNullableFixInfo { /** FixLocation of the target element in source code. */ private final FixLocation fixLocation; /** Error which will be resolved by this type change. */ private final ErrorMessage errorMessage; - /** Suggested annotation. */ - private final AnnotationConfig.Annotation annotation; private final ClassAndMethodInfo classAndMethodInfo; - public SuggestedFixInfo( - TreePath path, - FixLocation fixLocation, - ErrorMessage errorMessage, - AnnotationConfig.Annotation annotation) { + public SuggestedNullableFixInfo( + TreePath path, FixLocation fixLocation, ErrorMessage errorMessage) { this.classAndMethodInfo = new ClassAndMethodInfo(path); this.fixLocation = fixLocation; this.errorMessage = errorMessage; - this.annotation = annotation; } @Override @@ -57,33 +50,32 @@ public boolean equals(Object o) { if (this == o) { return true; } - if (!(o instanceof SuggestedFixInfo)) { + if (!(o instanceof SuggestedNullableFixInfo)) { return false; } - SuggestedFixInfo suggestedFixInfo = (SuggestedFixInfo) o; - return Objects.equals(fixLocation, suggestedFixInfo.fixLocation) - && Objects.equals(annotation, suggestedFixInfo.annotation) + SuggestedNullableFixInfo suggestedNullableFixInfo = (SuggestedNullableFixInfo) o; + return Objects.equals(fixLocation, suggestedNullableFixInfo.fixLocation) && Objects.equals( errorMessage.getMessageType().toString(), - suggestedFixInfo.errorMessage.getMessageType().toString()); + suggestedNullableFixInfo.errorMessage.getMessageType().toString()); } @Override public int hashCode() { - return Objects.hash(fixLocation, annotation, errorMessage.getMessageType().toString()); + return Objects.hash(fixLocation, errorMessage.getMessageType().toString()); } /** * returns string representation of content of an object. * - * @return string representation of contents of an object in a line seperated by tabs. + * @return string representation of contents of an object in a line separated by tabs. */ public String tabSeparatedToString() { return fixLocation.tabSeparatedToString() + '\t' + errorMessage.getMessageType().toString() + '\t' - + annotation + + "nullable" + '\t' + (classAndMethodInfo.getClazz() == null ? "null" @@ -100,8 +92,8 @@ public void initEnclosing() { } /** - * Creates header of an output file containing all {@link SuggestedFixInfo} written in string - * which values are separated by tabs. + * Creates header of an output file containing all {@link SuggestedNullableFixInfo} written in + * string which values are separated by tabs. * * @return string representation of the header separated by tabs. */ diff --git a/nullaway/src/main/java/com/uber/nullaway/fixserialization/qual/AnnotationConfig.java b/nullaway/src/main/java/com/uber/nullaway/fixserialization/qual/AnnotationConfig.java deleted file mode 100644 index dd95c1b623..0000000000 --- a/nullaway/src/main/java/com/uber/nullaway/fixserialization/qual/AnnotationConfig.java +++ /dev/null @@ -1,82 +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.fixserialization.qual; - -import com.uber.nullaway.annotations.EnsuresNonNull; - -/** Container object of any {@code @Nonnull} and {@code @Nullable} annotations. */ -public class AnnotationConfig { - - private Annotation nonNull; - private Annotation nullable; - - /** Container object of annotation. */ - public static class Annotation { - /** Fully qualified name. */ - private final String fullName; - - private Annotation(String fullName) { - this.fullName = fullName; - } - - /** - * Getter method for {@link Annotation#fullName}. - * - * @return fullName of the annotation. - */ - public String getFullName() { - return fullName; - } - - @Override - public String toString() { - return fullName; - } - } - - public AnnotationConfig() { - setFullNames("javax.annotation.Nonnull", "javax.annotation.Nullable"); - } - - public AnnotationConfig(String nullable, String nonNull) { - this(); - if (nullable == null || nullable.equals("") || nonNull == null || nonNull.equals("")) { - return; - } - setFullNames(nonNull, nullable); - } - - @EnsuresNonNull({"this.nonNull", "this.nullable"}) - public void setFullNames(String nonnullFullName, String nullableFullName) { - nonNull = new Annotation(nonnullFullName); - nullable = new Annotation(nullableFullName); - } - - public Annotation getNonNull() { - return nonNull; - } - - public Annotation getNullable() { - return nullable; - } -} diff --git a/nullaway/src/test/java/com/uber/nullaway/NullAwaySerializationTest.java b/nullaway/src/test/java/com/uber/nullaway/NullAwaySerializationTest.java index 351a6835f6..6aa907f12e 100644 --- a/nullaway/src/test/java/com/uber/nullaway/NullAwaySerializationTest.java +++ b/nullaway/src/test/java/com/uber/nullaway/NullAwaySerializationTest.java @@ -26,7 +26,7 @@ import com.uber.nullaway.fixserialization.FixSerializationConfig; import com.uber.nullaway.fixserialization.out.ErrorInfo; import com.uber.nullaway.fixserialization.out.FieldInitializationInfo; -import com.uber.nullaway.fixserialization.out.SuggestedFixInfo; +import com.uber.nullaway.fixserialization.out.SuggestedNullableFixInfo; import com.uber.nullaway.tools.DisplayFactory; import com.uber.nullaway.tools.ErrorDisplay; import com.uber.nullaway.tools.FieldInitDisplay; @@ -53,7 +53,7 @@ public class NullAwaySerializationTest extends NullAwayTestsBase { private final DisplayFactory fieldInitDisplayFactory; private static final String SUGGEST_FIX_FILE_NAME = "fixes.tsv"; - private static final String SUGGEST_FIX_FILE_HEADER = SuggestedFixInfo.header(); + private static final String SUGGEST_FIX_FILE_HEADER = SuggestedNullableFixInfo.header(); private static final String ERROR_FILE_NAME = "errors.tsv"; private static final String ERROR_FILE_HEADER = ErrorInfo.header(); private static final String FIELD_INIT_FILE_NAME = "field_init.tsv"; @@ -136,7 +136,7 @@ public void suggestNullableReturnSimpleTest() { "}") .setExpectedOutputs( new FixDisplay( - "javax.annotation.Nullable", + "nullable", "test(boolean)", "null", "METHOD", @@ -184,7 +184,7 @@ public void suggestNullableReturnSuperClassTest() { "}") .setExpectedOutputs( new FixDisplay( - "javax.annotation.Nullable", + "nullable", "test(boolean)", "null", "METHOD", @@ -222,7 +222,7 @@ public void suggestNullableParamSimpleTest() { "}") .setExpectedOutputs( new FixDisplay( - "javax.annotation.Nullable", + "nullable", "run(int,java.lang.Object)", "h", "PARAMETER", @@ -270,7 +270,7 @@ public void suggestNullableParamSubclassTest() { "}") .setExpectedOutputs( new FixDisplay( - "javax.annotation.Nullable", + "nullable", "test(java.lang.Object)", "o", "PARAMETER", @@ -309,7 +309,7 @@ public void suggestNullableParamThisConstructorTest() { "}") .setExpectedOutputs( new FixDisplay( - "javax.annotation.Nullable", + "nullable", "Test(java.lang.Object)", "o", "PARAMETER", @@ -353,7 +353,7 @@ public void suggestNullableParamGenericsTest() { "}") .setExpectedOutputs( new FixDisplay( - "javax.annotation.Nullable", + "nullable", "newStatement(T,java.util.ArrayList,boolean,boolean)", "lhs", "PARAMETER", @@ -389,12 +389,7 @@ public void suggestNullableFieldSimpleTest() { "}") .setExpectedOutputs( new FixDisplay( - "javax.annotation.Nullable", - "null", - "h", - "FIELD", - "com.uber.Super", - "com/uber/android/Super.java")) + "nullable", "null", "h", "FIELD", "com.uber.Super", "com/uber/android/Super.java")) .setFactory(fixDisplayFactory) .setOutputFileNameAndHeader(SUGGEST_FIX_FILE_NAME, SUGGEST_FIX_FILE_HEADER) .doTest(); @@ -427,12 +422,7 @@ public void suggestNullableFieldInitializationTest() { "}") .setExpectedOutputs( new FixDisplay( - "javax.annotation.Nullable", - "null", - "f", - "FIELD", - "com.uber.Super", - "com/uber/android/Super.java")) + "nullable", "null", "f", "FIELD", "com.uber.Super", "com/uber/android/Super.java")) .setFactory(fixDisplayFactory) .setOutputFileNameAndHeader(SUGGEST_FIX_FILE_NAME, SUGGEST_FIX_FILE_HEADER) .doTest(); @@ -483,33 +473,13 @@ public void suggestNullableFieldControlFlowTest() { "}") .setExpectedOutputs( new FixDisplay( - "javax.annotation.Nullable", - "null", - "h", - "FIELD", - "com.uber.Test", - "com/uber/android/Test.java"), + "nullable", "null", "h", "FIELD", "com.uber.Test", "com/uber/android/Test.java"), new FixDisplay( - "javax.annotation.Nullable", - "null", - "f", - "FIELD", - "com.uber.Test", - "com/uber/android/Test.java"), + "nullable", "null", "f", "FIELD", "com.uber.Test", "com/uber/android/Test.java"), new FixDisplay( - "javax.annotation.Nullable", - "null", - "g", - "FIELD", - "com.uber.Test", - "com/uber/android/Test.java"), + "nullable", "null", "g", "FIELD", "com.uber.Test", "com/uber/android/Test.java"), new FixDisplay( - "javax.annotation.Nullable", - "null", - "i", - "FIELD", - "com.uber.Test", - "com/uber/android/Test.java")) + "nullable", "null", "i", "FIELD", "com.uber.Test", "com/uber/android/Test.java")) .setFactory(fixDisplayFactory) .setOutputFileNameAndHeader(SUGGEST_FIX_FILE_NAME, SUGGEST_FIX_FILE_HEADER) .doTest(); @@ -535,12 +505,7 @@ public void suggestNullableNoInitializationFieldTest() { "}") .setExpectedOutputs( new FixDisplay( - "javax.annotation.Nullable", - "null", - "f", - "FIELD", - "com.uber.Test", - "com/uber/android/Test.java")) + "nullable", "null", "f", "FIELD", "com.uber.Test", "com/uber/android/Test.java")) .setFactory(fixDisplayFactory) .setOutputFileNameAndHeader(SUGGEST_FIX_FILE_NAME, SUGGEST_FIX_FILE_HEADER) .doTest(); @@ -629,58 +594,6 @@ public void skipSuggestFieldNullableExplicitNonnullTest() { .doTest(); } - @Test - public void suggestCustomAnnotTest() { - Path tempRoot = Paths.get(temporaryFolder.getRoot().getAbsolutePath(), "custom_annot"); - String output = tempRoot.toString(); - try { - Files.createDirectories(tempRoot); - FixSerializationConfig.Builder builder = - new FixSerializationConfig.Builder() - .setSuggest(true, false) - .setAnnotations("Custom.Nullable", "Custom.Nonnull") - .setOutputDirectory(output); - Path config = tempRoot.resolve("serializer.xml"); - Files.createFile(config); - configPath = config.toString(); - builder.writeAsXML(configPath); - } catch (IOException ex) { - throw new UncheckedIOException(ex); - } - SerializationTestHelper tester = new SerializationTestHelper<>(tempRoot); - 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(boolean flag) {", - " if(flag) {", - " return new Object();", - " } ", - " // BUG: Diagnostic contains: returning @Nullable", - " else return null;", - " }", - "}") - .setExpectedOutputs( - new FixDisplay( - "Custom.Nullable", - "test(boolean)", - "null", - "METHOD", - "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); @@ -1030,21 +943,21 @@ public void errorSerializationTestIdenticalLocalTypes() { .addSourceLines("com/uber/TestWithLocalTypes.java", sourceLines) .setExpectedOutputs( new FixDisplay( - "javax.annotation.Nullable", + "nullable", "returnsNullable()", "null", "METHOD", "com.uber.TestWithLocalTypes$1LocalType", "com/uber/TestWithLocalTypes.java"), new FixDisplay( - "javax.annotation.Nullable", + "nullable", "returnsNullable2()", "null", "METHOD", "com.uber.TestWithLocalTypes$2LocalType", "com/uber/TestWithLocalTypes.java"), new FixDisplay( - "javax.annotation.Nullable", + "nullable", "returnsNullable2()", "null", "METHOD",