FileRules

SUGGESTION

Simplification

View source code on GitHub

Suppression

Disable all rules by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$).* as compiler argument.

Table of contents
  1. PathOf
  2. PathOfVarargs
  3. PathIdentity
  4. PathResolveSiblingPath
  5. PathResolveSiblingString
  6. FilesReadStringWithCharset
  7. FilesReadString
  8. FilesReadAllLines
  9. FilesLines
  10. FilesWriteString
  11. FilesWrite
  12. FilesCreateTempFileToFile
  13. FilesCreateTempFileFileToPathToFile
  14. PathToFileMkdirsOrFilesExists
  15. FileMkdirsOrFileExists
  16. FilesNewInputStreamPathOf
  17. FilesNewInputStreamFileToPath
  18. FilesNewOutputStreamPathOf
  19. FilesNewOutputStreamFileToPath
  20. FilesNewBufferedReader
  21. FilesNewBufferedReaderWithCharset
  22. FilesNewBufferedWriter

PathOf

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("PathOf") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$PathOf).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 Path testPathOf() {
-  return Paths.get(URI.create("foo"));
+  return Path.of(URI.create("foo"));
 }

PathOfVarargs

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("PathOfVarargs") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$PathOfVarargs).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Path> testPathOfVarargs() {
-  return ImmutableSet.of(Paths.get("foo"), Paths.get("bar", "baz", "qux"));
+  return ImmutableSet.of(Path.of("foo"), Path.of("bar", "baz", "qux"));
 }

PathIdentity

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("PathIdentity") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$PathIdentity).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 Path testPathIdentity() {
-  return Path.of("foo").toFile().toPath();
+  return Path.of("foo");
 }

PathResolveSiblingPath

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("PathResolveSiblingPath") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$PathResolveSiblingPath).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 Path testPathResolveSiblingPath() {
-  return Path.of("foo").getParent().resolve(Path.of("bar"));
+  return Path.of("foo").resolveSibling(Path.of("bar"));
 }

PathResolveSiblingString

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("PathResolveSiblingString") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$PathResolveSiblingString).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 Path testPathResolveSiblingString() {
-  return Path.of("foo").getParent().resolve("bar");
+  return Path.of("foo").resolveSibling("bar");
 }

FilesReadStringWithCharset

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesReadStringWithCharset") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesReadStringWithCharset).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 String testFilesReadStringWithCharset() throws IOException {
-  return new String(Files.readAllBytes(Paths.get("foo")), StandardCharsets.ISO_8859_1);
+  return Files.readString(Paths.get("foo"), StandardCharsets.ISO_8859_1);
 }

FilesReadString

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesReadString") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesReadString).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 String testFilesReadString() throws IOException {
-  return Files.readString(Paths.get("foo"), StandardCharsets.UTF_8);
+  return Files.readString(Paths.get("foo"));
 }

FilesReadAllLines

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesReadAllLines") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesReadAllLines).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 List<String> testFilesReadAllLines() throws IOException {
-  return Files.readAllLines(Path.of("foo"), StandardCharsets.UTF_8);
+  return Files.readAllLines(Path.of("foo"));
 }

FilesLines

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesLines") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesLines).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 Stream<String> testFilesLines() throws IOException {
-  return Files.lines(Path.of("foo"), StandardCharsets.UTF_8);
+  return Files.lines(Path.of("foo"));
 }

FilesWriteString

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesWriteString") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesWriteString).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Path> testFilesWriteString() throws IOException {
   return ImmutableSet.of(
-      Files.writeString(Path.of("foo"), "bar", StandardCharsets.UTF_8),
-      Files.writeString(
-          Path.of("baz"), "qux", StandardCharsets.UTF_8, StandardOpenOption.CREATE));
+      Files.writeString(Path.of("foo"), "bar"),
+      Files.writeString(Path.of("baz"), "qux", StandardOpenOption.CREATE));
 }

FilesWrite

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesWrite") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesWrite).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Path> testFilesWrite() throws IOException {
   return ImmutableSet.of(
-      Files.write(Path.of("foo"), ImmutableList.of("bar"), StandardCharsets.UTF_8),
-      Files.write(
-          Path.of("baz"),
-          ImmutableList.of("qux"),
-          StandardCharsets.UTF_8,
-          StandardOpenOption.CREATE));
+      Files.write(Path.of("foo"), ImmutableList.of("bar")),
+      Files.write(Path.of("baz"), ImmutableList.of("qux"), StandardOpenOption.CREATE));
 }

FilesCreateTempFileToFile

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesCreateTempFileToFile") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesCreateTempFileToFile).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<File> testFilesCreateTempFileToFile() throws IOException {
   return ImmutableSet.of(
-      File.createTempFile("foo", "bar"), File.createTempFile("baz", "qux", null));
+      Files.createTempFile("foo", "bar").toFile(), Files.createTempFile("baz", "qux").toFile());
 }

FilesCreateTempFileFileToPathToFile

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesCreateTempFileFileToPathToFile") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesCreateTempFileFileToPathToFile).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 File testFilesCreateTempFileFileToPathToFile() throws IOException {
-  return File.createTempFile("foo", "bar", new File("baz"));
+  return Files.createTempFile(new File("baz").toPath(), "foo", "bar").toFile();
 }

PathToFileMkdirsOrFilesExists

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("PathToFileMkdirsOrFilesExists") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$PathToFileMkdirsOrFilesExists).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Boolean> testPathToFileMkdirsOrFilesExists() {
   return ImmutableSet.of(
-      Files.exists(Path.of("foo")) || Path.of("foo").toFile().mkdirs(),
-      !Files.exists(Path.of("bar")) && !Path.of("bar").toFile().mkdirs());
+      Path.of("foo").toFile().mkdirs() || Files.exists(Path.of("foo")),
+      !Path.of("bar").toFile().mkdirs() && !Files.exists(Path.of("bar")));
 }

FileMkdirsOrFileExists

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FileMkdirsOrFileExists") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FileMkdirsOrFileExists).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Boolean> testFileMkdirsOrFileExists() {
   return ImmutableSet.of(
-      new File("foo").exists() || new File("foo").mkdirs(),
-      !new File("bar").exists() && !new File("bar").mkdirs());
+      new File("foo").mkdirs() || new File("foo").exists(),
+      !new File("bar").mkdirs() && !new File("bar").exists());
 }

FilesNewInputStreamPathOf

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesNewInputStreamPathOf") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesNewInputStreamPathOf).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 InputStream testFilesNewInputStreamPathOf() throws IOException {
-  return new FileInputStream("foo");
+  return Files.newInputStream(Path.of("foo"));
 }

FilesNewInputStreamFileToPath

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesNewInputStreamFileToPath") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesNewInputStreamFileToPath).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 InputStream testFilesNewInputStreamFileToPath() throws IOException {
-  return new FileInputStream(new File("foo"));
+  return Files.newInputStream(new File("foo").toPath());
 }

FilesNewOutputStreamPathOf

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesNewOutputStreamPathOf") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesNewOutputStreamPathOf).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 OutputStream testFilesNewOutputStreamPathOf() throws IOException {
-  return new FileOutputStream("foo");
+  return Files.newOutputStream(Path.of("foo"));
 }

FilesNewOutputStreamFileToPath

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesNewOutputStreamFileToPath") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesNewOutputStreamFileToPath).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 OutputStream testFilesNewOutputStreamFileToPath() throws IOException {
-  return new FileOutputStream(new File("foo"));
+  return Files.newOutputStream(new File("foo").toPath());
 }

FilesNewBufferedReader

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesNewBufferedReader") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesNewBufferedReader).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<BufferedReader> testFilesNewBufferedReader() throws IOException {
   return ImmutableSet.of(
-      Files.newBufferedReader(Path.of("foo"), StandardCharsets.UTF_8),
-      new BufferedReader(new InputStreamReader(Files.newInputStream(Path.of("bar")))));
+      Files.newBufferedReader(Path.of("foo")), Files.newBufferedReader(Path.of("bar")));
 }

FilesNewBufferedReaderWithCharset

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesNewBufferedReaderWithCharset") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesNewBufferedReaderWithCharset).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 BufferedReader testFilesNewBufferedReaderWithCharset() throws IOException {
-  return new BufferedReader(
-      new InputStreamReader(Files.newInputStream(Path.of("foo")), StandardCharsets.UTF_8));
+  return Files.newBufferedReader(Path.of("foo"), StandardCharsets.UTF_8);
 }

FilesNewBufferedWriter

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesNewBufferedWriter") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesNewBufferedWriter).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<BufferedWriter> testFilesNewBufferedWriter() throws IOException {
   return ImmutableSet.of(
-      Files.newBufferedWriter(Path.of("foo"), StandardCharsets.UTF_8),
-      Files.newBufferedWriter(Path.of("bar"), StandardCharsets.UTF_8, StandardOpenOption.CREATE));
+      Files.newBufferedWriter(Path.of("foo")),
+      Files.newBufferedWriter(Path.of("bar"), StandardOpenOption.CREATE));
 }

Copyright © 2017-2026 Picnic Technologies BV