Integrated: 8231599: NPE when loading a preview classfile from a future Java version
Jan Lahoda
jlahoda at openjdk.java.net
Wed Nov 11 09:13:59 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
This pull request has now been integrated.
Changeset: 129ff97f
Author: Jan Lahoda <jlahoda at openjdk.org>
URL: https://git.openjdk.java.net/jdk/commit/129ff97f
Stats: 137 lines in 2 files changed: 135 ins; 0 del; 2 mod
8231599: NPE when loading a preview classfile from a future Java version
Reviewed-by: vromero
-------------
PR: https://git.openjdk.java.net/jdk/pull/1123
More information about the compiler-dev
mailing list