Skip to content

Commit

Permalink
Revert "Add serialization format version to fix serialization output (u…
Browse files Browse the repository at this point in the history
…ber#688)"

This reverts commit dd75827.
  • Loading branch information
msridhar committed Jul 18, 2023
1 parent 8e92cc7 commit 6ee02e6
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import javax.annotation.Nullable;

/**
* Serializer class where all generated files in Fix Serialization package is created through APIs
Expand All @@ -48,35 +46,12 @@ public class Serializer {
/** Path to write suggested fix metadata. */
private final Path fieldInitializationOutputPath;

/**
* Version for all serialized outputs. Outputs formats may change overtime, this version is
* serialized to keep track of changes.
*/
public static final int SERIALIZATION_VERSION = 1;

public Serializer(FixSerializationConfig config) {
String outputDirectory = config.outputDirectory;
this.errorOutputPath = Paths.get(outputDirectory, "errors.tsv");
this.suggestedFixesOutputPath = Paths.get(outputDirectory, "fixes.tsv");
this.fieldInitializationOutputPath = Paths.get(outputDirectory, "field_init.tsv");
initializeOutputFiles(config);
serializeVersion(outputDirectory);
}

/**
* Serializes the {@link Serializer#SERIALIZATION_VERSION} as {@code string} in
* <b>serialization_version.txt</b> file under root output directory for all serialized outputs.
*
* @param outputDirectory Path to root directory for all serialized outputs.
*/
private void serializeVersion(@Nullable String outputDirectory) {
Path versionOutputPath = Paths.get(outputDirectory).resolve("serialization_version.txt");
try (Writer fileWriter =
Files.newBufferedWriter(versionOutputPath.toFile().toPath(), Charset.defaultCharset())) {
fileWriter.write(SERIALIZATION_VERSION + "");
} catch (IOException exception) {
throw new RuntimeException("Could not serialize output version", exception);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.google.errorprone.util.ASTHelpers;
import com.sun.tools.javac.code.Symbol;
import com.uber.nullaway.fixserialization.FixSerializationConfig;
import com.uber.nullaway.fixserialization.Serializer;
import com.uber.nullaway.fixserialization.out.ErrorInfo;
import com.uber.nullaway.fixserialization.out.FieldInitializationInfo;
import com.uber.nullaway.fixserialization.out.SuggestedNullableFixInfo;
Expand All @@ -43,7 +42,6 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -1619,47 +1617,4 @@ public void suggestNullableArgumentOnBytecodeClassFileInfoOnly() {
.doTest();
}
}

@Test
public void verifySerializationVersionIsSerialized() {
SerializationTestHelper<FixDisplay> tester = new SerializationTestHelper<>(root);
tester
.setArgs(
Arrays.asList(
"-d",
temporaryFolder.getRoot().getAbsolutePath(),
"-XepOpt:NullAway:AnnotatedPackages=com.uber",
"-XepOpt:NullAway:SerializeFixMetadata=true",
"-XepOpt:NullAway:FixSerializationConfigPath=" + configPath))
// Just to run serialization features, the serialized fixes are not point of interest in
// this test.
.addSourceLines(
"com/uber/Test.java",
"package com.uber;",
"public class Test {",
" Object run() {",
" // BUG: Diagnostic contains: returning @Nullable expression",
" return null;",
" }",
"}")
.setExpectedOutputs(
new FixDisplay(
"nullable", "run()", "null", "METHOD", "com.uber.Test", "com/uber/Test.java"))
.setFactory(fixDisplayFactory)
.setOutputFileNameAndHeader(SUGGEST_FIX_FILE_NAME, SUGGEST_FIX_FILE_HEADER)
.doTest();

Path serializationVersionPath = root.resolve("serialization_version.txt");
try {
List<String> lines = Files.readAllLines(serializationVersionPath);
// Check if it contains only one line.
Preconditions.checkArgument(lines.size() == 1);
// Check the serialized version.
Preconditions.checkArgument(
Integer.parseInt(lines.get(0)) == Serializer.SERIALIZATION_VERSION);
} catch (IOException e) {
throw new RuntimeException(
"Could not read serialization version at path: " + serializationVersionPath, e);
}
}
}

0 comments on commit 6ee02e6

Please sign in to comment.