Skip to content

Feature: Detection of the Java Class File version #147

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

Closed
jorsol opened this issue Jan 29, 2023 · 3 comments · Fixed by #170
Closed

Feature: Detection of the Java Class File version #147

jorsol opened this issue Jan 29, 2023 · 3 comments · Fixed by #170

Comments

@jorsol
Copy link
Contributor

jorsol commented Jan 29, 2023

Sometimes it might be useful to have a way to read the class file version of a compiled class to know which version of Java was used to compile that class.

One example of such use case is in the maven-compiler-plugin, where it should be possible to detect the class file version of a previous compilation and compare it with the current version of the target/release, this way it allows to detect if the class needs recompilation or not.

@rfscholte
Copy link
Member

You have my interest. Not sure, but this might be related to the classfile-api .

@jorsol
Copy link
Contributor Author

jorsol commented Jan 30, 2023

I was thinking of something a lot simpler than using ASM or similar, will try to provide a PR soon.

@rfscholte
Copy link
Member

rfscholte commented Jan 31, 2023

It looks like with the classfile api it will be as easy as

ClassModel classModel = ClassModel.of(bytes);
int majorVersion = classModel.majorVersion();
int minorVersion = classModel.minorVersion();

There's no target release yet, so it makes sense to add something similar. With a multirelease jar we can also redirect to the official class-api.

sandbox sourcerepo: https://github.com/openjdk/jdk-sandbox/tree/classfile-api-branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants