From 3001f07fd1d985658626c9f997433c746a9e0587 Mon Sep 17 00:00:00 2001 From: svc-excavator-bot Date: Thu, 17 Jul 2025 14:33:31 +0000 Subject: [PATCH] Excavator: Upgrades Baseline to the latest version --- build.gradle | 2 +- .../javaformat/gradle/ExecutableTransform.java | 8 ++++---- .../javaformat/gradle/JavaFormatExtension.java | 4 ++-- .../gradle/spotless/PalantirJavaFormatStep.java | 5 +++-- .../javaformat/intellij/FormatterProvider.java | 4 ++-- .../intellij/PalantirJavaFormatSettings.java | 4 ++-- .../PalantirJavaFormatFormattingServiceTest.java | 4 ++-- .../com/palantir/javaformat/BenchmarkMultiFiles.java | 4 ++-- .../bootstrap/BootstrappingFormatterService.java | 10 ++++------ .../bootstrap/NativeImageFormatterService.java | 10 ++++------ .../java/com/palantir/javaformat/BreakBehaviour.java | 10 +++++----- .../com/palantir/javaformat/java/DebugRenderer.java | 10 ++++------ .../palantir/javaformat/java/FormatFileCallable.java | 4 ++-- .../java/com/palantir/javaformat/java/Formatter.java | 4 ++-- .../java/com/palantir/javaformat/java/JsonSink.java | 4 ++-- .../main/java/com/palantir/javaformat/java/Main.java | 4 ++-- .../main/java/com/palantir/javaformat/java/Trees.java | 4 ++-- .../com/palantir/javaformat/java/FileBasedTests.java | 4 ++-- 18 files changed, 47 insertions(+), 52 deletions(-) diff --git a/build.gradle b/build.gradle index 926632798..9338ecb0d 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { dependencies { classpath 'com.palantir.jakartapackagealignment:jakarta-package-alignment:0.6.0' classpath 'com.gradle.publish:plugin-publish-plugin:1.3.1' - classpath 'com.palantir.baseline:gradle-baseline-java:6.43.0' + classpath 'com.palantir.baseline:gradle-baseline-java:6.44.0' classpath 'com.palantir.gradle.consistentversions:gradle-consistent-versions:2.36.0' classpath 'com.palantir.gradle.externalpublish:gradle-external-publish-plugin:1.19.0' classpath 'com.palantir.gradle.failure-reports:gradle-failure-reports:1.14.0' diff --git a/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/ExecutableTransform.java b/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/ExecutableTransform.java index 94339036c..d57fbd2ff 100644 --- a/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/ExecutableTransform.java +++ b/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/ExecutableTransform.java @@ -18,6 +18,7 @@ import java.io.File; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; @@ -46,7 +47,6 @@ public abstract class ExecutableTransform implements TransformAction getInputArtifact(); - @SuppressWarnings("for-rollout:PreferUncheckedIoException") @Override public void transform(TransformOutputs outputs) { File inputFile = getInputArtifact().get().getAsFile(); @@ -55,11 +55,11 @@ public void transform(TransformOutputs outputs) { Files.copy(inputFile.toPath(), outputFile.toPath(), StandardCopyOption.REPLACE_EXISTING); makeFileExecutable(outputFile.toPath()); } catch (IOException e) { - throw new RuntimeException(String.format("Failed to create executable file %s", outputFile.toPath()), e); + throw new UncheckedIOException( + String.format("Failed to create executable file %s", outputFile.toPath()), e); } } - @SuppressWarnings("for-rollout:PreferUncheckedIoException") private static void makeFileExecutable(Path pathToExe) { try { Set existingPermissions = Files.getPosixFilePermissions(pathToExe); @@ -73,7 +73,7 @@ private static void makeFileExecutable(Path pathToExe) { PosixFilePermission.OTHERS_EXECUTE)) .collect(Collectors.toSet())); } catch (IOException e) { - throw new RuntimeException("Failed to set execute permissions on native-image", e); + throw new UncheckedIOException("Failed to set execute permissions on native-image", e); } } } diff --git a/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/JavaFormatExtension.java b/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/JavaFormatExtension.java index b8791d832..174944335 100644 --- a/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/JavaFormatExtension.java +++ b/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/JavaFormatExtension.java @@ -19,6 +19,7 @@ import com.google.common.base.Suppliers; import com.google.common.collect.Iterables; import com.palantir.javaformat.java.FormatterService; +import java.io.UncheckedIOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; @@ -41,13 +42,12 @@ public FormatterService serviceLoad() { @SuppressWarnings("for-rollout:NullAway") private FormatterService serviceLoadInternal() { - @SuppressWarnings("for-rollout:PreferUncheckedIoException") URL[] jarUris = configuration.getFiles().stream() .map(file -> { try { return file.toURI().toURL(); } catch (MalformedURLException e) { - throw new RuntimeException("Unable to convert URI to URL: " + file, e); + throw new UncheckedIOException("Unable to convert URI to URL: " + file, e); } }) .toArray(URL[]::new); diff --git a/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/spotless/PalantirJavaFormatStep.java b/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/spotless/PalantirJavaFormatStep.java index dd8d62b20..9b209a1fe 100644 --- a/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/spotless/PalantirJavaFormatStep.java +++ b/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/spotless/PalantirJavaFormatStep.java @@ -22,6 +22,7 @@ import java.io.File; import java.io.IOException; import java.io.Serializable; +import java.io.UncheckedIOException; import java.util.function.Supplier; import org.gradle.api.artifacts.Configuration; @@ -79,7 +80,7 @@ static final class State implements Serializable { this.memoizedFormatter = memoizedFormatter; } - @SuppressWarnings({"NullableProblems", "for-rollout:PreferUncheckedIoException"}) + @SuppressWarnings("NullableProblems") FormatterFunc createFormat() { return input -> { try { @@ -92,7 +93,7 @@ FormatterFunc createFormat() { return memoizedFormatter.get().formatSourceReflowStringsAndFixImports(input); } catch (IOException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } }; } diff --git a/idea-plugin/src/main/java/com/palantir/javaformat/intellij/FormatterProvider.java b/idea-plugin/src/main/java/com/palantir/javaformat/intellij/FormatterProvider.java index cd38a6876..a8032901a 100644 --- a/idea-plugin/src/main/java/com/palantir/javaformat/intellij/FormatterProvider.java +++ b/idea-plugin/src/main/java/com/palantir/javaformat/intellij/FormatterProvider.java @@ -34,6 +34,7 @@ import com.palantir.javaformat.bootstrap.NativeImageFormatterService; import com.palantir.javaformat.java.FormatterService; import java.io.IOException; +import java.io.UncheckedIOException; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; @@ -207,12 +208,11 @@ private static URL[] toUrlsUnchecked(List paths) { .toArray(URL[]::new); } - @SuppressWarnings("for-rollout:PreferUncheckedIoException") private static List listDirAsUrlsUnchecked(Path dir) { try (Stream list = Files.list(dir)) { return list.collect(Collectors.toList()); } catch (IOException e) { - throw new RuntimeException("Couldn't list dir: " + dir, e); + throw new UncheckedIOException("Couldn't list dir: " + dir, e); } } diff --git a/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettings.java b/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettings.java index 283f031ee..3ac978c26 100644 --- a/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettings.java +++ b/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettings.java @@ -24,6 +24,7 @@ import com.palantir.javaformat.java.JavaFormatterOptions; import com.palantir.sls.versions.OrderableSlsVersion; import java.io.IOException; +import java.io.UncheckedIOException; import java.net.URI; import java.util.List; import java.util.Optional; @@ -113,7 +114,6 @@ Optional getImplementationVersion() { return Optional.ofNullable(FormatterProvider.getPluginDescriptor().getVersion()); } - @SuppressWarnings("for-rollout:PreferUncheckedIoException") Optional computeFormatterVersion() { return getImplementationClassPath().map(classpath -> classpath.stream() .flatMap(uri -> { @@ -127,7 +127,7 @@ Optional computeFormatterVersion() { } return Stream.empty(); } catch (IOException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } }) .findFirst() diff --git a/idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingServiceTest.java b/idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingServiceTest.java index 5ab1fd9c8..bdab25130 100644 --- a/idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingServiceTest.java +++ b/idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingServiceTest.java @@ -41,6 +41,7 @@ import com.palantir.javaformat.intellij.PalantirJavaFormatSettings.State; import java.io.File; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -103,7 +104,6 @@ protected Project getProject() { @NotNull protected LightProjectDescriptor getProjectDescriptor() { return new DefaultLightProjectDescriptor() { - @SuppressWarnings("for-rollout:PreferUncheckedIoException") @Override public Sdk getSdk() { try { @@ -111,7 +111,7 @@ public Sdk getSdk() { .createJdk( "java 1.11", new File(System.getProperty("java.home")).getCanonicalPath(), false); } catch (IOException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } } }; diff --git a/palantir-java-format-benchmarks/src/jmh/java/com/palantir/javaformat/BenchmarkMultiFiles.java b/palantir-java-format-benchmarks/src/jmh/java/com/palantir/javaformat/BenchmarkMultiFiles.java index b1b006d46..f0385ad1d 100644 --- a/palantir-java-format-benchmarks/src/jmh/java/com/palantir/javaformat/BenchmarkMultiFiles.java +++ b/palantir-java-format-benchmarks/src/jmh/java/com/palantir/javaformat/BenchmarkMultiFiles.java @@ -19,6 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -47,7 +48,6 @@ public static class BenchmarkState { final List filesToFormat = getFilesToFormat(); - @SuppressWarnings("for-rollout:PreferUncheckedIoException") private static List getFilesToFormat() { Path srcJavaFormatFiles = Paths.get(".") .toAbsolutePath() @@ -57,7 +57,7 @@ private static List getFilesToFormat() { .map(path -> path.toAbsolutePath().toString())) { return paths.collect(Collectors.toList()); } catch (IOException e) { - throw new RuntimeException("Couldn't list src files: " + srcJavaFormatFiles, e); + throw new UncheckedIOException("Couldn't list src files: " + srcJavaFormatFiles, e); } } } diff --git a/palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/BootstrappingFormatterService.java b/palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/BootstrappingFormatterService.java index 86ba95936..92d734449 100644 --- a/palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/BootstrappingFormatterService.java +++ b/palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/BootstrappingFormatterService.java @@ -27,6 +27,7 @@ import com.palantir.javaformat.java.FormatterService; import com.palantir.javaformat.java.Replacement; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.file.Path; import java.util.Collection; import java.util.List; @@ -50,33 +51,30 @@ public BootstrappingFormatterService(Path jdkPath, Integer jdkMajorVersion, List this.implementationClassPath = implementationClassPath; } - @SuppressWarnings("for-rollout:PreferUncheckedIoException") @Override public ImmutableList getFormatReplacements(String input, Collection> ranges) { try { return getFormatReplacementsInternal(input, ranges); } catch (IOException e) { - throw new RuntimeException("Error running formatter command", e); + throw new UncheckedIOException("Error running formatter command", e); } } - @SuppressWarnings("for-rollout:PreferUncheckedIoException") @Override public String formatSourceReflowStringsAndFixImports(String input) { try { return runFormatterCommand(input); } catch (IOException e) { - throw new RuntimeException("Error running formatter command", e); + throw new UncheckedIOException("Error running formatter command", e); } } - @SuppressWarnings("for-rollout:PreferUncheckedIoException") @Override public String fixImports(String input) throws FormatterException { try { return runFormatterCommand(input); } catch (IOException e) { - throw new RuntimeException("Error running formatter command", e); + throw new UncheckedIOException("Error running formatter command", e); } } diff --git a/palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/NativeImageFormatterService.java b/palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/NativeImageFormatterService.java index 5a858b843..0d2152ee8 100644 --- a/palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/NativeImageFormatterService.java +++ b/palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/NativeImageFormatterService.java @@ -26,6 +26,7 @@ import com.palantir.javaformat.java.FormatterService; import com.palantir.javaformat.java.Replacement; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.file.Path; import java.util.Collection; import java.util.List; @@ -42,7 +43,6 @@ public NativeImageFormatterService(Path nativeImagePath) { this.nativeImagePath = nativeImagePath; } - @SuppressWarnings("for-rollout:PreferUncheckedIoException") @Override public ImmutableList getFormatReplacements(String input, Collection> ranges) { try { @@ -60,27 +60,25 @@ public ImmutableList getFormatReplacements(String input, Collection } return MAPPER.readValue(output.get(), new TypeReference<>() {}); } catch (IOException e) { - throw new RuntimeException("Error running the native image command", e); + throw new UncheckedIOException("Error running the native image command", e); } } - @SuppressWarnings("for-rollout:PreferUncheckedIoException") @Override public String formatSourceReflowStringsAndFixImports(String input) { try { return runFormatterCommand(input); } catch (IOException e) { - throw new RuntimeException("Error running the native image command", e); + throw new UncheckedIOException("Error running the native image command", e); } } - @SuppressWarnings("for-rollout:PreferUncheckedIoException") @Override public String fixImports(String input) { try { return runFormatterCommand(input); } catch (IOException e) { - throw new RuntimeException("Error running the native image command", e); + throw new UncheckedIOException("Error running the native image command", e); } } diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/BreakBehaviour.java b/palantir-java-format/src/main/java/com/palantir/javaformat/BreakBehaviour.java index 4a255c1b6..d2ba639bb 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/BreakBehaviour.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/BreakBehaviour.java @@ -23,6 +23,7 @@ import com.palantir.javaformat.doc.Doc; import com.palantir.javaformat.doc.Level; import java.io.IOException; +import java.io.UncheckedIOException; import org.derive4j.ArgOption; import org.derive4j.Data; @@ -73,7 +74,6 @@ public interface Cases { */ static class Json extends JsonSerializer { - @SuppressWarnings("for-rollout:PreferUncheckedIoException") @Override public void serialize(BreakBehaviour value, JsonGenerator gen, SerializerProvider serializers) throws IOException { @@ -83,7 +83,7 @@ public void serialize(BreakBehaviour value, JsonGenerator gen, SerializerProvide try { gen.writeObjectField("type", "breakThisLevel"); } catch (IOException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } return null; }) @@ -92,7 +92,7 @@ public void serialize(BreakBehaviour value, JsonGenerator gen, SerializerProvide gen.writeObjectField("type", "preferBreakingLastInnerLevel"); gen.writeObjectField("keepIndentWhenInlined", keepIndentWhenInlined); } catch (IOException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } return null; }) @@ -100,7 +100,7 @@ public void serialize(BreakBehaviour value, JsonGenerator gen, SerializerProvide try { gen.writeObjectField("type", "inlineSuffix"); } catch (IOException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } return null; }) @@ -109,7 +109,7 @@ public void serialize(BreakBehaviour value, JsonGenerator gen, SerializerProvide gen.writeObjectField("type", "breakOnlyIfInnerLevelsThenFitOnOneLine"); gen.writeObjectField("keepIndentWhenInlined", keepIndentWhenInlined); } catch (IOException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } return null; }); diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/DebugRenderer.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/DebugRenderer.java index ba96a024b..0b02212df 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/DebugRenderer.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/DebugRenderer.java @@ -36,6 +36,7 @@ import com.palantir.javaformat.doc.State; import com.palantir.javaformat.doc.Token; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -51,7 +52,6 @@ static Path getOutputFile() { return publicDir.resolve("output.js"); } - @SuppressWarnings("for-rollout:PreferUncheckedIoException") static void render( JavaInput javaInput, OpsOutput opsOutput, @@ -72,7 +72,7 @@ static void render( try { Files.write(getOutputFile(), javascript.getBytes(StandardCharsets.UTF_8)); } catch (IOException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } } @@ -85,7 +85,6 @@ private static String outputAsString(JavaOutput javaOutput) { return output.toString(); } - @SuppressWarnings("for-rollout:PreferUncheckedIoException") private static String opsJson(OpsOutput opsOutput) { ArrayNode arrayNode = OBJECT_MAPPER.createArrayNode(); @@ -143,16 +142,15 @@ private static String opsJson(OpsOutput opsOutput) { try { return OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(arrayNode); } catch (JsonProcessingException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } } - @SuppressWarnings("for-rollout:PreferUncheckedIoException") private static String jsonEscapedString(String javaInput) { try { return OBJECT_MAPPER.writeValueAsString(javaInput); } catch (JsonProcessingException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } } diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/FormatFileCallable.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/FormatFileCallable.java index 385f9afc5..fb455056b 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/FormatFileCallable.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/FormatFileCallable.java @@ -23,6 +23,7 @@ import com.google.common.collect.RangeSet; import com.google.common.collect.TreeRangeSet; import com.palantir.javaformat.Utils; +import java.io.UncheckedIOException; import java.util.concurrent.Callable; /** Encapsulates information about a file to be formatted, including which parts of the file to format. */ @@ -53,14 +54,13 @@ public String call() throws FormatterException { return formatFile(formatter); } - @SuppressWarnings("for-rollout:PreferUncheckedIoException") private String formatReplacements(Formatter formatter) throws FormatterException { ImmutableList replacements = formatter.getFormatReplacements(input, characterRanges(input).asRanges()); try { return MAPPER.writeValueAsString(replacements); } catch (JsonProcessingException e) { - throw new RuntimeException("Error serializing replacement output", e); + throw new UncheckedIOException("Error serializing replacement output", e); } } diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/Formatter.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/Formatter.java index 68a03cade..ef8dab408 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/Formatter.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/Formatter.java @@ -45,6 +45,7 @@ import com.sun.tools.javac.util.Log; import com.sun.tools.javac.util.Options; import java.io.IOException; +import java.io.UncheckedIOException; import java.net.URI; import java.util.Collection; import javax.tools.Diagnostic; @@ -163,7 +164,6 @@ static JavaOutput format( return javaOutput; } - @SuppressWarnings("for-rollout:PreferUncheckedIoException") static JCCompilationUnit parseJcCompilationUnit(Context context, String sourceText) throws FormatterException { DiagnosticCollector diagnostics = new DiagnosticCollector<>(); context.put(DiagnosticListener.class, diagnostics); @@ -174,7 +174,7 @@ static JCCompilationUnit parseJcCompilationUnit(Context context, String sourceTe fileManager.setLocation(StandardLocation.PLATFORM_CLASS_PATH, ImmutableList.of()); } catch (IOException e) { // impossible - throw new RuntimeException(e); + throw new UncheckedIOException(e); } SimpleJavaFileObject source = new SimpleJavaFileObject(URI.create("source"), JavaFileObject.Kind.SOURCE) { @Override diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JsonSink.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JsonSink.java index 23a86d157..6aa69eac2 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JsonSink.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JsonSink.java @@ -26,6 +26,7 @@ import com.palantir.javaformat.doc.Obs.FinishLevelNode; import com.palantir.javaformat.doc.Obs.Sink; import com.palantir.javaformat.doc.State; +import java.io.UncheckedIOException; import java.util.HashMap; import java.util.Map; import java.util.Optional; @@ -86,13 +87,12 @@ public FinishLevelNode writeLevelNode(int levelNodeId, int parentExplorationId, return acceptedExplorationId -> json.put("acceptedExplorationId", acceptedExplorationId); } - @SuppressWarnings("for-rollout:PreferUncheckedIoException") @Override public String getOutput() { try { return OBJECT_MAPPER.writeValueAsString(rootNode); } catch (JsonProcessingException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } } diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/Main.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/Main.java index fd21f52e2..74bb37f03 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/Main.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/Main.java @@ -22,6 +22,7 @@ import java.io.InputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; +import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -183,13 +184,12 @@ private int formatFiles(CommandLineOptions parameters, JavaFormatterOptions opti return allOk ? 0 : 1; } - @SuppressWarnings("for-rollout:PreferUncheckedIoException") private int formatStdin(CommandLineOptions parameters, JavaFormatterOptions options) { String input; try { input = new String(ByteStreams.toByteArray(inStream), UTF_8); } catch (IOException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } String stdinFilename = parameters.assumeFilename().orElse(STDIN_FILENAME); boolean ok = true; diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/Trees.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/Trees.java index d92d0a8fd..ead97b908 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/Trees.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/Trees.java @@ -27,6 +27,7 @@ import com.sun.tools.javac.tree.Pretty; import com.sun.tools.javac.tree.TreeInfo; import java.io.IOException; +import java.io.UncheckedIOException; import javax.lang.model.element.Name; /** Utilities for working with {@link Tree}s. */ @@ -48,13 +49,12 @@ static int getEndPosition(Tree expression, TreePath path) { } /** Returns the source text for the node. */ - @SuppressWarnings("for-rollout:PreferUncheckedIoException") static String getSourceForNode(Tree node, TreePath path) { CharSequence source; try { source = path.getCompilationUnit().getSourceFile().getCharContent(false); } catch (IOException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } return source.subSequence(getStartPosition(node), getEndPosition(node, path)) .toString(); diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/java/FileBasedTests.java b/palantir-java-format/src/test/java/com/palantir/javaformat/java/FileBasedTests.java index 736a5761d..f7ae66fe7 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/java/FileBasedTests.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/java/FileBasedTests.java @@ -29,6 +29,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -142,12 +143,11 @@ private Path getOutputTestPath(String testName) { return fullTestPath.resolve(testName + ".output"); } - @SuppressWarnings("for-rollout:PreferUncheckedIoException") public void writeFormatterOutput(String testName, String output) { try (BufferedWriter writer = Files.newBufferedWriter(getOutputTestPath(testName))) { writer.append(output); } catch (IOException e) { - throw new RuntimeException("Couldn't recreate test output for " + testName, e); + throw new UncheckedIOException("Couldn't recreate test output for " + testName, e); } } }