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

Jan Lahoda jlahoda at openjdk.java.net
Mon Nov 9 12:54:06 UTC 2020


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

-------------

Commit messages:
 - 8231599: NPE when loading a preview classfile from a future Java version

Changes: https://git.openjdk.java.net/jdk/pull/1123/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=1123&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8231599
  Stats: 137 lines in 2 files changed: 135 ins; 0 del; 2 mod
  Patch: https://git.openjdk.java.net/jdk/pull/1123.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/1123/head:pull/1123

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


More information about the compiler-dev mailing list