Skip to content

Error-prone-javac doesn't support --release when run from Gradle with Java 8 #1237

@AlexLandau

Description

@AlexLandau

I don't necessarily expect this to get fixed in any way, but the behavior here was something of a mystery to me until I started digging through the code, so I'm writing this up in the hopes of saving someone else some confusion.

Description of the problem / feature request:

The short version: When error-prone-javac is run from a Java 8 JDK, --release will look a bit like it's supported but misconfigured, when in reality it's incapable of working at all.

We have a Gradle build running in Java 8 that currently sets the bootstrap classpath for all its builds (some targeting Java 6 and some Java 8). It uses ErrorProne via the gradle-errorprone-plugin, specifically using error-prone-javac at version 9+181-r4173-1.

Since the compiler is "Java 9", I assumed I'd be able to use the --release feature to replace our use of bootstrap classpaths. However, when I added it to the compilerArgs, I would get the error message (for example) release version 8 not supported regardless of what version I tried to use.

The issue is that while support for the --release argument is determined by the compiler version, the actual data it needs to use is tied to the JDK in use. Namely, it looks in the JDK's location on the file system (via "java.home") and expects to find a file within named lib/ct.sym with the associated data. Of course, a Java 8 JDK won't have this information. (It does have a file named lib/ct.sym, but per the JEP it's not the same information or format.)

I believe that in principle this could be fixed by adding the Java 9 ct.sym file to the error-prone-javac jar and loading it from the classpath in the JDK if getting the ct.sym file from the file system fails. (I had kind of assumed that "load the information from the classpath" was how the feature worked in the first place!) That said, this may be a narrow use case and there are workarounds (using Java 9+ for running Gradle, continuing to use bootstrap classpaths). I'm also not sure if this information varies in different Java distributions. There may be easier options around improving error messages or documentation if some kind of change is warranted.

What version of Error Prone are you using?

error-prone-javac 9+181-r4173-1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions