JDK-8200338 : 4.1: Restrict the legal values of ClassFile.minor_version
  • Type: Bug
  • Component: specification
  • Sub-Component: vm
  • Affected Version: 11
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2018-03-27
  • Updated: 2019-05-29
  • Resolved: 2018-12-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 12
12Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
During a discussion of how preview features will be realized (http://mail.openjdk.java.net/pipermail/jdk-dev/2018-March/000992.html), it was pointed out that 4.1's traditional "contiguous range" rule is deficient in two ways, both involving a non-zero minor_version:

1. It forces an SE 13 JVM (57.0) to accept 56.65535. This forced acceptance is bad because 56.65535 indicates a class file that depends on preview features of SE 12 and hence is unsupportable on SE 13.

2. It forces an SE 13 JVM (57.0) to reject 57.65535. This forced rejection is bad because 57.65535 indicates a class file that depends on preview features of SE 13 and hence is of great interest to this JVM (assuming --enable-preview is also given).

minor_version had a legacy purpose in JDK 1.0 and 1.1, but JDK 1.2 made it redundant. Since 1.2, compilers have set it to zero, and HotSpot has required it to be zero in "new" class files. For example, HotSpot in JDK 1.2 accepted 46.0 but not 46.<non-zero>; HotSpot in JDK 8 accepted 52.0 but not 52.<non-zero>. Formally, for every Java SE Platform N since N=2, the RI has rejected a non-zero minor_version if the major_version is 44+N. (This implies that JDK 8 accepts, say, 51.<non-zero> class files from the JDK 7 era, but this is not a concern because JDK 7 itself did not produce or accept them, instead producing and accepting only 51.0.)

In SE 12 and beyond, minor_version will again have purpose. Preview features use it to denote class files that are release-bound, and it will be a useful field for experimental features too. Accordingly, it is helpful to constrain the values of minor_version for each major_version, rather than allowing the wide ranges found in Table 4.1-A of JVMS10 (https://docs.oracle.com/javase/specs/jvms/se10/html/jvms-4.html#jvms-4.1-200-B.2).

A possible way to specify this is to enumerate legal versions as follows: (platforms before SE 9 omitted for brevity)

9     45.*, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0, 52.0, 53.0
10   45.*, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0, 52.0, 53.0, 54.0
11   45.*, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0, 52.0, 53.0, 54.0, 55.0
12   45.*, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0, 52.0, 53.0, 54.0, 55.0, 56.0, 56.65535
13   45.*, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0, 52.0, 53.0, 54.0, 55.0, 56.0, 57.0, 57.65535
Comments
Given that the minor version of the class file format has played different roles over time, we decided to streamline the presentation by separating the treatment of major and minor version numbers, and making the constraints on minor_version dependent on value of major_version. Out of an abundance of caution for third-party JVM implementations, we decided to continue the longstanding JVMS practice of accepting any minor_version when the major_version is 45 through 55 inclusive.
14-12-2018

Something like this: The values of the minor_version and major_version items are the minor and major version numbers of this class file. Together, a major and a minor version number determine the version of the class file format. If a class file has major version number M and minor version number m, we denote the version of its class file format as M.m. ~~Thus, class file format versions may be ordered lexicographically, for example, 1.5 < 2.0 < 2.1.~~ A Java Virtual Machine implementation **which conforms to Java SE Platform version V** can support a class file format of version ~~v~~ **M.m** if and only if ~~v lies in some contiguous range Mi.0 ��� v ��� Mj.m. The range is based on the version of the Java SE Platform to which the implementation conforms. An implementation which conforms to a given Java SE Platform version must support the range specified in Table 4.1-A for that version, and no other range.~~ **M is a _supported major version_ for the Java SE Platform version V, as defined in Table 4.1-A, and one of the following are true:** - **m is 0** - **M is 45 (in this case m may be any 16-bit integer)** - **M is the highest supported major version for Java SE Platform version V, m is 65535, and the JVM is running in _preview mode_** **A JVM is running in "preview mode" if ...** [or maybe this is defined in another section, like 5.2] (For historical cases, **in Table 4.1-A** the JDK version is shown instead of the Java SE Platform version.) _Table 4.1-A. class file format version ranges (by Java SE Platform)_ Java SE class file format **major** version range 1.0.2 ~~45.0 ��� v ��� 45.3~~ **45 ��� M ��� 45** 1.1 ~~45.0 ��� v ��� 45.65535~~ **45 ��� M ��� 45** 1.2 ~~45.0 ��� v ��� 46.0~~ **45 ��� M ��� 46** 1.3 ~~45.0 ��� v ��� 47.0~~ **45 ��� M ��� 47** 1.4 ~~45.0 ��� v ��� 48.0~~ **45 ��� M ��� 48** 5.0 ~~45.0 ��� v ��� 49.0~~ **45 ��� M ��� 49** 6 ~~45.0 ��� v ��� 50.0~~ **45 ��� M ��� 50** 7 ~~45.0 ��� v ��� 51.0~~ **45 ��� M ��� 51** 8 ~~45.0 ��� v ��� 52.0~~ **45 ��� M ��� 52** 9 ~~45.0 ��� v ��� 53.0~~ **45 ��� M ��� 53** 10 ~~45.0 ��� v ��� 54.0~~ **45 ��� M ��� 54**
27-03-2018

Seems that it is also necessary to describe "preview mode" as a first-class concept in JVMS, so that we can explain that, e.g., in 11, version 55.65535 is supported iff the JVM is running in preview mode.
27-03-2018