Repository: bazelbuild/bazel
Issue: Java runfiles library no longer compiles with Java 8
Labels: type: bug
team-Rules-Java
untriaged

### Description of the bug:


In Bazel 6.0.0rc2, the Java runfiles library no longer builds with Java 8:

```
ERROR: /home/runner/.cache/bazel/_bazel_runner/6bc610921f14939de4c55cf170d55a62/external/bazel_tools/tools/java/runfiles/BUILD:1:13: Building external/bazel_tools/tools/java/runfiles/librunfiles.jar (2 source files) failed: (Exit 1): java failed: error executing command (from target @bazel_tools//tools/java/runfiles:runfiles) external/remotejdk11_linux/bin/java -XX:-CompactStrings '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED' ... (remaining 16 arguments skipped)
external/bazel_tools/tools/java/runfiles/Runfiles.java:413: error: no suitable constructor found for FileReader(String,Charset)
    try (BufferedReader r = new BufferedReader(new FileReader(path, StandardCharsets.UTF_8))) {
                                               ^
    constructor FileReader.FileReader(String) is not applicable
      (actual and formal argument lists differ in length)
    constructor FileReader.FileReader(File) is not applicable
      (actual and formal argument lists differ in length)
    constructor FileReader.FileReader(FileDescriptor) is not applicable
      (actual and formal argument lists differ in length)
```

### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.


1. Point `JAVA_HOME` to a Java 8 JDK
2. In any Bazel project, run `bazel build @bazel_tools//tools/java/runfiles --java_runtime_version=local_jdk_8`.

### Which operating system are you running Bazel on?


Any

### What is the output of `bazel info release`?


6.0.0rc2

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.


_No response_

### What's the output of `git remote get-url origin; git rev-parse master; git rev-parse HEAD` ?


_No response_

### Have you found anything relevant by searching the web?

_No response_

### Any other information, logs, or outputs that you want to share?

_No response_

Issue comments:
@bazel-io flag
Submitted a fix in https://github.com/bazelbuild/bazel/pull/16851
@bazel-io fork 6.0.0

Pull request review comments:

Patch that resolved the issue:
diff --git a/tools/java/runfiles/Runfiles.java b/tools/java/runfiles/Runfiles.java
index 171d1b2078ade4..c705e1db48bd94 100644
--- a/tools/java/runfiles/Runfiles.java
+++ b/tools/java/runfiles/Runfiles.java
@@ -17,7 +17,6 @@
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.lang.ref.SoftReference;
@@ -410,7 +409,9 @@ private static Map<Preloaded.RepoMappingKey, String> loadRepositoryMapping(Strin
       return Collections.emptyMap();
     }
 
-    try (BufferedReader r = new BufferedReader(new FileReader(path, StandardCharsets.UTF_8))) {
+    try (BufferedReader r =
+        new BufferedReader(
+            new InputStreamReader(new FileInputStream(path), StandardCharsets.UTF_8))) {
       return Collections.unmodifiableMap(
           r.lines()
               .filter(line -> !line.isEmpty())


Test patch: