Skip to content

8355652: Parse ClassFileFormatVersion from ClassFileVersion #26406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

gustavosimon
Copy link
Contributor

@gustavosimon gustavosimon commented Jul 20, 2025

8355652: add new method to return ClassFileFormatVersion from ClassFileVersion.

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8355652: Parse ClassFileFormatVersion from ClassFileVersion (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26406/head:pull/26406
$ git checkout pull/26406

Update a local copy of the PR:
$ git checkout pull/26406
$ git pull https://git.openjdk.org/jdk.git pull/26406/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26406

View PR using the GUI difftool:
$ git pr show -t 26406

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26406.diff

Using Webrev

Link to Webrev Comment


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change requires a CSR request matching fixVersion 26 to be approved (needs to be created)

Issue

  • JDK-8355652: Parse ClassFileFormatVersion from ClassFileVersion (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26406/head:pull/26406
$ git checkout pull/26406

Update a local copy of the PR:
$ git checkout pull/26406
$ git pull https://git.openjdk.org/jdk.git pull/26406/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26406

View PR using the GUI difftool:
$ git pr show -t 26406

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26406.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 20, 2025

👋 Welcome back gustavosimon! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jul 20, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk
Copy link

openjdk bot commented Jul 20, 2025

@gustavosimon The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Jul 20, 2025
@gustavosimon gustavosimon changed the title 8355652: add new method to return ClassFileFormatVersion from ClassFileVersion. 8355652: Parse ClassFileFormatVersion from ClassFileVersion Jul 20, 2025
@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 20, 2025
@mlbridge
Copy link

mlbridge bot commented Jul 20, 2025

Webrevs

@gustavosimon
Copy link
Contributor Author

gustavosimon commented Jul 20, 2025

@liach I know that I'm commenting on a weekend but it's to you see tomorrow.

I'm commiting a 1.0 version for this implementation - to get your feedback about

I think we should create some unit tests for this API and classes involved. Where do you think that is the most appropriate location in the project to do it?

@liach
Copy link
Member

liach commented Jul 20, 2025

I think we should create some unit tests for this API and classes involved. Where do you think that is the most appropriate location in the project to do it?

Unit tests for java.lang.classfile reside in test/jdk/jdk/classfile. They can be run with make test TEST=jdk/jdk/classfile.

@gustavosimon
Copy link
Contributor Author

I think we should create some unit tests for this API and classes involved. Where do you think that is the most appropriate location in the project to do it?

Unit tests for java.lang.classfile reside in test/jdk/jdk/classfile. They can be run with make test TEST=jdk/jdk/classfile.

Great! Thanks!

@Override
public Optional<ClassFileFormatVersion> formatVersion() {
try {
return Optional.of(ClassFileFormatVersion.fromMajor(majorVersion));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should check the minor version to be 0 for major versions 54 and later.

Copy link
Contributor Author

@gustavosimon gustavosimon Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
        }
    }            

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this logic is wrong. It's more like the check in

public static boolean isSupportedClassFileVersion(int major, int minor) {
if (major < ClassFile.JAVA_1_VERSION || major > ClassFile.latestMajorVersion()) return false;
// for major version is between 45 and 55 inclusive, the minor version may be any value
if (major < ClassFile.JAVA_12_VERSION) return true;
// otherwise, the minor version must be 0 or 65535
return minor == 0 || (minor == ClassFile.PREVIEW_MINOR_VERSION && major == ClassFile.latestMajorVersion());
}

 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)); 
 } 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it can be reused in another points?

ClassFileFormatVersion and Optional are more user-oriented classes; internal code don't really ever use these two types, so I don't think you need to extract this logic specifically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean about the rule the version - similar to isSupportedClassFileVersion method

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't think so. I intentionally proposed the original RFE so we have one place where we can consolidate this handling, and that place should be here instead of some other place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I'll do this way

@@ -25,6 +25,8 @@
package jdk.internal.classfile.impl;

import java.lang.classfile.ClassFileVersion;
import java.lang.reflect.ClassFileFormatVersion;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: copyright year :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@myankelev I updated the copyright year in ClassFileVersionImpl

@liach
Copy link
Member

liach commented Jul 21, 2025

/csr

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Jul 21, 2025
@openjdk
Copy link

openjdk bot commented Jul 21, 2025

@liach has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@gustavosimon please create a CSR request for issue JDK-8355652 with the correct fix version. This pull request cannot be integrated until the CSR request is approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org csr Pull request needs approved CSR before integration rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

3 participants