RFR: 8355652: Parse ClassFileFormatVersion from ClassFileVersion

simon duke at openjdk.org
Mon Jul 21 16:08:32 UTC 2025


On Mon, 21 Jul 2025 02:50:48 GMT, Chen Liang <liach at openjdk.org> wrote:

>> Do you mean something like this? 
>> 
>> 
>> @Override
>>     public Optional<ClassFileFormatVersion> formatVersion() {
>>         if (majorVersion < 54 || minorVersion != 0) {
>>             return Optional.empty();
>>         }
>>         try {
>>             return Optional.of(ClassFileFormatVersion.fromMajor(majorVersion));
>>         } catch (IllegalArgumentException e) {
>>             return Optional.empty();
>>         }
>>     }
>
> No, this logic is wrong. It's more like the check in https://github.com/openjdk/jdk/blob/441dbde2c3c915ffd916e39a5b4a91df5620d7f3/src/java.base/share/classes/jdk/internal/misc/VM.java#L174-L180
> 
> 
>  public Optional<ClassFileFormatVersion> formatVersion() { 
>      if (majorVersion < ClassFile.JAVA_1_VERSION || majorVersion > ClassFile.latestMajorVersion()) return Optional.empty(); 
>      // for major version is between 45 and 55 inclusive, the minor version may be any value 
>      if (majorVersion >= ClassFile.JAVA_12_VERSION && minorVersion != 0) return Optional.empty(); 
>      // otherwise, only minor version 0 is a defined, persistent format
>      return Optional.of(ClassFileFormatVersion.fromMajor(majorVersion)); 
>  }

Got it. Could you have this hook in a private class method or a static public method? 
Maybe it can be reused in another points?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26406#discussion_r2219638656


More information about the core-libs-dev mailing list