RFR: 8231599: NPE when loading a preview classfile from a future Java version

Vicente Romero vromero at openjdk.java.net
Mon Nov 9 17:34:58 UTC 2020

On Mon, 9 Nov 2020 12:47:30 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> The javac's ClassReader accepts class files with major version that is +1 higher than the current platform's major version. See https://bugs.openjdk.java.net/browse/JDK-6330997 for more information.
> A problem is that when this too-new class file is a preview class file, the Preview class will attempt to produce a warning (or error) which includes the user-readable name of the Java platform, and it cannot find the name of the future platform name.
> If the major version of the class file is >+1 higher than the current platform's, there is no such problem: ClassReader will reject to analyze the class file right away.
> The proposed (middle ground) fix here is that ClassReader will reject all preview class files with major version > current platform's major version. It will keep accepting non-preview class files with major version +1 than the current.
> With this patch, the standard error is produced:
> brokenMajorVersionWithPreview/test/Test.java:1: error: cannot access C
> class Test extends C {}
>                    ^
>   bad class file: brokenMajorVersionWithPreview/classes/C.class
>     class file has wrong version 61.65535, should be 60.0
>     Please remove or make sure it appears in the correct subdirectory of the classpath.
> 1 error
> Alternatives include:
>  * reject all class files with major version > current
>  * accept preview class files with major version +1 than the current, and attempt the generate a sensible (future) platform name

looks sensible to me


Marked as reviewed by vromero (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/1123

More information about the compiler-dev mailing list