Unable to build buck. Java class file version error.

Ђорђе Љубинковић
2023-02-23T14:08:57Z

## Description

I've cloned the [repo](https://github.com/facebook/buck) but I'm unable to build buck.
There was an identical issue: #2355 which got closed.

## Steps to reproduce
- Clone the repo and build with `ant`:
```bash
$ git clone --depth 1 https://github.com/facebook/buck.git
$ cd buck
$ ant
```
- Fails when executing the `./bin/buck build --show-output buck` command with the following:
```bash
Buck encountered an internal error
com.google.common.util.concurrent.ExecutionError: java.lang.UnsupportedClassVersionError: com/facebook/buck/remoteexecution/proto/RESessionID has been compiled by a more recent version of the Java Runtime (class file version 62.0), this version of the Java Runtime only recognizes class file versions up to 55.0
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2216)
at com.google.common.cache.LocalCache.get(LocalCache.java:4147)
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4151)
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:5140)
at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:5146)
at com.facebook.buck.core.config.ConfigViewCache.getView(ConfigViewCache.java:46)
at com.facebook.buck.core.config.BuckConfig.getView(BuckConfig.java:101)
at com.facebook.buck.cli.MainRunner.isRemoteExecutionAutoEnabled(MainRunner.java:1785)
at com.facebook.buck.cli.MainRunner.isRemoteExecutionBuild(MainRunner.java:1796)
at com.facebook.buck.cli.MainRunner.runMainWithExitCode(MainRunner.java:762)
at com.facebook.buck.cli.MainRunner.runMainThenExit(MainRunner.java:476)
at com.facebook.buck.cli.MainWithNailgun.nailMain(MainWithNailgun.java:77)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.facebook.nailgun.NGSession.runImpl(NGSession.java:313)
at com.facebook.nailgun.NGSession.run(NGSession.java:199)
Caused by: java.lang.UnsupportedClassVersionError: com/facebook/buck/remoteexecution/proto/RESessionID has been compiled by a more recent version of the Java Runtime (class file version 62.0), this version of the Java Runtime only recognizes class file versions up to 55.0
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:555)
at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:458)
at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:452)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:451)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)
at java.base/java.lang.Class.getMethodsRecursive(Class.java:3307)
at java.base/java.lang.Class.getMethod0(Class.java:3293)
at java.base/java.lang.Class.getMethod(Class.java:2106)
at com.facebook.buck.core.config.ConfigViewCache$ConfigViewCacheLoader.load(ConfigViewCache.java:67)
at com.facebook.buck.core.config.ConfigViewCache$ConfigViewCacheLoader.load(ConfigViewCache.java:1)
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3708)
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2416)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2299)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2212)
... 17 more
```

I've tried compiling with java 8, 11 and 18... 8 and 11 pass, although when trying to build buck with java 8 it says:
- `Warning: JAVA_HOME is set to "/Library/Java/JavaVirtualMachines/jdk1.8.0_341.jdk/Contents/Home", which looks like a Java 8 path, but Buck requires Java 11. Ignoring JAVA_HOME. Set BUCK_RESPECT_JAVA_HOME to 1 to disable this behavior.`

`ant` command fails when using java 18 with the following:
```bash
compile:
[javac] Compiling 1 source file to /Users/ljd1bg/Desktop/buck/ant-out/classes
[javac] [compiled 86 lines in 343 ms: 250.7 lines/s]
[javac] ----------
[javac] 1. ERROR in /Users/ljd1bg/Desktop/buck/src/com/facebook/buck/jvm/java/abi/java11/SourceVersionUtils.java (at line 27)
[javac] switch (version) {
[javac] ^^^^^^^
[javac] The enum constant RELEASE_12 should have a corresponding case label in this enum switch on SourceVersion. To suppress this problem, add a comment //$CASES-OMITTED$ on the line above the 'default:'
[javac] ----------
[javac] 2. ERROR in /Users/ljd1bg/Desktop/buck/src/com/facebook/buck/jvm/java/abi/java11/SourceVersionUtils.java (at line 27)
[javac] switch (version) {
[javac] ^^^^^^^
[javac] The enum constant RELEASE_13 should have a corresponding case label in this enum switch on SourceVersion. To suppress this problem, add a comment //$CASES-OMITTED$ on the line above the 'default:'
[javac] ----------
[javac] 3. ERROR in /Users/ljd1bg/Desktop/buck/src/com/facebook/buck/jvm/java/abi/java11/SourceVersionUtils.java (at line 27)
[javac] switch (version) {
[javac] ^^^^^^^
[javac] The enum constant RELEASE_14 should have a corresponding case label in this enum switch on SourceVersion. To suppress this problem, add a comment //$CASES-OMITTED$ on the line above the 'default:'
[javac] ----------
[javac] 4. ERROR in /Users/ljd1bg/Desktop/buck/src/com/facebook/buck/jvm/java/abi/java11/SourceVersionUtils.java (at line 27)
[javac] switch (version) {
[javac] ^^^^^^^
[javac] The enum constant RELEASE_15 should have a corresponding case label in this enum switch on SourceVersion. To suppress this problem, add a comment //$CASES-OMITTED$ on the line above the 'default:'
[javac] ----------
[javac] 5. ERROR in /Users/ljd1bg/Desktop/buck/src/com/facebook/buck/jvm/java/abi/java11/SourceVersionUtils.java (at line 27)
[javac] switch (version) {
[javac] ^^^^^^^
[javac] The enum constant RELEASE_16 should have a corresponding case label in this enum switch on SourceVersion. To suppress this problem, add a comment //$CASES-OMITTED$ on the line above the 'default:'
[javac] ----------
[javac] 6. ERROR in /Users/ljd1bg/Desktop/buck/src/com/facebook/buck/jvm/java/abi/java11/SourceVersionUtils.java (at line 27)
[javac] switch (version) {
[javac] ^^^^^^^
[javac] The enum constant RELEASE_17 should have a corresponding case label in this enum switch on SourceVersion. To suppress this problem, add a comment //$CASES-OMITTED$ on the line above the 'default:'
[javac] ----------
[javac] 7. ERROR in /Users/ljd1bg/Desktop/buck/src/com/facebook/buck/jvm/java/abi/java11/SourceVersionUtils.java (at line 27)
[javac] switch (version) {
[javac] ^^^^^^^
[javac] The enum constant RELEASE_18 should have a corresponding case label in this enum switch on SourceVersion. To suppress this problem, add a comment //$CASES-OMITTED$ on the line above the 'default:'
[javac] ----------
[javac] 7 problems (7 errors)

BUILD FAILED
/Users/ljd1bg/Desktop/buck/build.xml:613: The following error occurred while executing this line:
/Users/ljd1bg/Desktop/buck/build.xml:555: Compile failed; see the compiler error output for details.

Total time: 4 seconds
```

## Java Version

```bash
java -version
java version "11.0.16.1" 2022-08-18 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.16.1+1-LTS-1)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.16.1+1-LTS-1, mixed mode)

javac -version
javac 11.0.16.1
```