diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index dff819a2467..5e4cfb7a87f 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -90,6 +90,9 @@ jobs:
- name: 'Test'
shell: bash
run: mvn test -B
+ - name: 'SanityCheck'
+ shell: bash
+ run: mvn rewrite:dryRun
- name: 'Javadoc'
shell: bash
run: mvn -P '!examples' javadoc:javadoc
diff --git a/.gitignore b/.gitignore
index a389004c5f8..940c4971260 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,8 +8,9 @@
# intellij
.idea/ant.xml
-.idea/codestream.xml
+.idea/checkstyle-idea.xml
.idea/codeStyleSettings.xml
+.idea/codestream.xml
.idea/compiler.xml
.idea/copyright
.idea/dataSources.ids
@@ -21,6 +22,7 @@
.idea/libraries
.idea/misc.xml
.idea/modules.xml
+.idea/palantir-java-format.xml
.idea/shelf
.idea/tasks.xml
.idea/uiDesigner.xml
diff --git a/check_api/pom.xml b/check_api/pom.xml
index 0c40bb08aef..b73432cec4b 100644
--- a/check_api/pom.xml
+++ b/check_api/pom.xml
@@ -49,6 +49,12 @@
jspecify
${jspecify.version}
+
+ jakarta.annotation
+ jakarta.annotation-api
+ 1.3.5
+ provided
+
io.github.eisop
@@ -103,6 +109,12 @@
${truth.version}
test
+
+ jakarta.inject
+ jakarta.inject-api
+ 1.0.3
+ test
+
org.mockito
diff --git a/check_api/src/main/java/com/google/errorprone/apply/DescriptionBasedDiff.java b/check_api/src/main/java/com/google/errorprone/apply/DescriptionBasedDiff.java
index 3d60e808b5e..c04d5931853 100644
--- a/check_api/src/main/java/com/google/errorprone/apply/DescriptionBasedDiff.java
+++ b/check_api/src/main/java/com/google/errorprone/apply/DescriptionBasedDiff.java
@@ -26,7 +26,7 @@
import com.sun.tools.javac.tree.EndPosTable;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import java.net.URI;
-import java.nio.file.Paths;
+import java.nio.file.Path;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
@@ -68,7 +68,7 @@ private DescriptionBasedDiff(
URI sourceFileUri = compilationUnit.getSourceFile().toUri();
this.sourcePath =
(sourceFileUri.isAbsolute() && Objects.equals(sourceFileUri.getScheme(), "file"))
- ? Paths.get(sourceFileUri).toAbsolutePath().toString()
+ ? Path.of(sourceFileUri).toAbsolutePath().toString()
: sourceFileUri.getPath();
this.ignoreOverlappingFixes = ignoreOverlappingFixes;
this.importsToAdd = new LinkedHashSet<>();
diff --git a/core/pom.xml b/core/pom.xml
index eaaab041d4a..cd7864ad3d7 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -74,6 +74,12 @@
pcollections
4.0.1
+
+ jakarta.annotation
+ jakarta.annotation-api
+ 1.3.5
+ provided
+
com.google.guava
@@ -99,6 +105,11 @@
dataflow-errorprone
${dataflow.version}
+
+ jakarta.inject
+ jakarta.inject-api
+ 1.0.3
+
com.google.auto.value
diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/checkreturnvalue/ExternalCanIgnoreReturnValue.java b/core/src/main/java/com/google/errorprone/bugpatterns/checkreturnvalue/ExternalCanIgnoreReturnValue.java
index a112d6a84a1..6925c4bc9f6 100644
--- a/core/src/main/java/com/google/errorprone/bugpatterns/checkreturnvalue/ExternalCanIgnoreReturnValue.java
+++ b/core/src/main/java/com/google/errorprone/bugpatterns/checkreturnvalue/ExternalCanIgnoreReturnValue.java
@@ -37,7 +37,7 @@
import com.sun.tools.javac.util.List;
import java.io.IOException;
import java.io.UncheckedIOException;
-import java.nio.file.Paths;
+import java.nio.file.Path;
import java.util.Optional;
import java.util.stream.Stream;
@@ -98,13 +98,13 @@ enum ConfigParser {
AS_STRINGS {
@Override
MethodPredicate load(String file) throws IOException {
- return configByInterpretingMethodsAsStrings(MoreFiles.asCharSource(Paths.get(file), UTF_8));
+ return configByInterpretingMethodsAsStrings(MoreFiles.asCharSource(Path.of(file), UTF_8));
}
},
PARSE_TOKENS {
@Override
MethodPredicate load(String file) throws IOException {
- return configByParsingApiObjects(MoreFiles.asCharSource(Paths.get(file), UTF_8));
+ return configByParsingApiObjects(MoreFiles.asCharSource(Path.of(file), UTF_8));
}
};
diff --git a/core/src/test/java/com/google/errorprone/ErrorProneJavacPluginTest.java b/core/src/test/java/com/google/errorprone/ErrorProneJavacPluginTest.java
index a86f04c13b3..02ee948ba59 100644
--- a/core/src/test/java/com/google/errorprone/ErrorProneJavacPluginTest.java
+++ b/core/src/test/java/com/google/errorprone/ErrorProneJavacPluginTest.java
@@ -50,7 +50,6 @@
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.nio.file.Paths;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.stream.Stream;
@@ -215,7 +214,7 @@ public void applyToPatchFile() throws IOException {
assertThat(
Files.readAllLines(patchFile, UTF_8).stream()
.filter(l -> l.startsWith("--- "))
- .map(l -> Paths.get(l.substring("--- ".length())).getFileName().toString())
+ .map(l -> Path.of(l.substring("--- ".length())).getFileName().toString())
.collect(toImmutableList()))
.containsExactly("A.java", "B.java");
}
diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/apidiff/CompilationBuilderHelpers.java b/core/src/test/java/com/google/errorprone/bugpatterns/apidiff/CompilationBuilderHelpers.java
index ebc4375b8e1..abfcd25b508 100644
--- a/core/src/test/java/com/google/errorprone/bugpatterns/apidiff/CompilationBuilderHelpers.java
+++ b/core/src/test/java/com/google/errorprone/bugpatterns/apidiff/CompilationBuilderHelpers.java
@@ -31,7 +31,6 @@
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.BasicFileAttributes;
@@ -62,7 +61,7 @@ public SourceBuilder(File tempFolder) {
@CanIgnoreReturnValue
public SourceBuilder addSourceLines(String name, String... lines) throws IOException {
- Path filePath = Paths.get(tempFolder.getAbsolutePath(), name);
+ Path filePath = Path.of(tempFolder.getAbsolutePath(), name);
sources.add(filePath);
Files.write(filePath, Arrays.asList(lines), UTF_8, StandardOpenOption.CREATE);
return this;
diff --git a/docgen/src/main/java/com/google/errorprone/BugPatternFileGenerator.java b/docgen/src/main/java/com/google/errorprone/BugPatternFileGenerator.java
index 400603105f2..7d065a5443b 100644
--- a/docgen/src/main/java/com/google/errorprone/BugPatternFileGenerator.java
+++ b/docgen/src/main/java/com/google/errorprone/BugPatternFileGenerator.java
@@ -33,7 +33,6 @@
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -110,7 +109,7 @@ public boolean processLine(String line) throws IOException {
}
// replace spaces in filename with underscores
- Path checkPath = Paths.get(pattern.name.replace(' ', '_') + ".md");
+ Path checkPath = Path.of(pattern.name.replace(' ', '_') + ".md");
try (Writer writer = Files.newBufferedWriter(outputDir.resolve(checkPath), UTF_8)) {
diff --git a/docgen/src/main/java/com/google/errorprone/DocGenTool.java b/docgen/src/main/java/com/google/errorprone/DocGenTool.java
index 57142e5bd52..de155eab51f 100644
--- a/docgen/src/main/java/com/google/errorprone/DocGenTool.java
+++ b/docgen/src/main/java/com/google/errorprone/DocGenTool.java
@@ -34,7 +34,6 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.nio.file.Paths;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -93,15 +92,15 @@ public static void main(String[] args) throws IOException {
Options options = new Options();
new JCommander(options).parse(args);
- Path bugPatterns = Paths.get(options.bugPatterns);
+ Path bugPatterns = Path.of(options.bugPatterns);
if (!Files.exists(bugPatterns)) {
usage("Cannot find bugPatterns file: " + options.bugPatterns);
}
- Path explanationDir = Paths.get(options.explanations);
+ Path explanationDir = Path.of(options.explanations);
if (!Files.exists(explanationDir)) {
usage("Cannot find explanations dir: " + options.explanations);
}
- Path wikiDir = Paths.get(options.docsRepository);
+ Path wikiDir = Path.of(options.docsRepository);
Files.createDirectories(wikiDir);
Path bugpatternDir = wikiDir.resolve("bugpattern");
if (!Files.exists(bugpatternDir)) {
diff --git a/docgen_processor/pom.xml b/docgen_processor/pom.xml
index 7d97a4cb4ca..74263886907 100644
--- a/docgen_processor/pom.xml
+++ b/docgen_processor/pom.xml
@@ -45,6 +45,12 @@
guava
${guava.version}
+
+ jakarta.annotation
+ jakarta.annotation-api
+ 1.3.5
+ provided
+
com.google.auto.service
auto-service-annotations
diff --git a/pom.xml b/pom.xml
index 16c54102b27..b7944f7863c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -112,9 +112,40 @@
${project.build.directory}/dependency-reduced-pom.xml
+
+ org.openrewrite.maven
+ rewrite-maven-plugin
+ 6.23.0
+
+
+ com.google.openrewrite.SanityCheck
+
+
+ **/refaster/testdata/**
+
+ true
+ true
+
+
+
+ org.openrewrite.recipe
+ rewrite-migrate-java
+ 3.21.1
+
+
+ org.openrewrite.recipe
+ rewrite-rewrite
+ 0.15.0
+
+
+
+
+ org.openrewrite.maven
+ rewrite-maven-plugin
+
org.apache.maven.plugins
maven-enforcer-plugin
diff --git a/rewrite.yml b/rewrite.yml
new file mode 100644
index 00000000000..19bf6fabaac
--- /dev/null
+++ b/rewrite.yml
@@ -0,0 +1,8 @@
+---
+type: specs.openrewrite.org/v1beta/recipe
+name: com.google.openrewrite.SanityCheck
+displayName: Apply Java & Maven best practices
+description: Comprehensive code quality recipe combining modernization, security, and best practices.
+recipeList:
+ - org.openrewrite.java.migrate.Java8toJava11
+---