Skip to content
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

scan all versions in multi-version-jar #61

Closed
wants to merge 1 commit into from
Closed

scan all versions in multi-version-jar #61

wants to merge 1 commit into from

Conversation

rPraml
Copy link

@rPraml rPraml commented May 3, 2022

@iloveeclipse
Copy link
Member

@rPraml : thanks for contributing.

  1. Please sign SCA agreement, otherwise we can't accept the patch
  2. Please check contribution guidelines / git history for appropriate commit title
  3. Please describe in the commit message the fix
  4. ideally we would like to see a regression test added.

See https://github.com/eclipse-jdt/.github/blob/main/CONTRIBUTING.md

Copy link
Author

@rPraml rPraml left a comment

Choose a reason for hiding this comment

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

I've identified 3 places, where multi-release-jars are not properly handled according to the spec.
These changes should make ecj more javac comatible.

It would be great, if someone can pick up this work and write a test, as I have not much knowledge how to do this in the eclipse ecosystem

if (!Files.exists(this.releasePath)) {
this.releasePath = null;
for (int version = Integer.parseInt(this.compliance); version >= 9; version--) {
this.releasePath = this.fs.getPath("/", "META-INF", "versions", String.valueOf(version)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Copy link
Author

Choose a reason for hiding this comment

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

according to
https://docs.oracle.com/javase/10/docs/specs/jar/jar.html#multi-release-jar-files
all versions down to 9 have to be checked.
this.compliance should be always a major version accroding to the spec, so parseInt should work

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably it would be good to parse the compliance only once (same below) and cache it in a field?

ZipEntry entry = zipFile.getEntry(releasePath);
if (entry != null) {
path = releasePath;
for (int version = Integer.parseInt(release); version >= 9; version--) {
Copy link
Author

Choose a reason for hiding this comment

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

This is practically the same code as above.

} catch (Exception e) {
e.printStackTrace();
// move on to the default
for (int version = Integer.parseInt(this.compliance); version >= 9; version--) {
Copy link
Author

Choose a reason for hiding this comment

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

and here, we search for the module-info.class, which should be the fix for the bug

Copy link
Member

Choose a reason for hiding this comment

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

Any reason why It's being done in ClasspathJar instead of org.eclipse.jdt.internal.core.builder.ClasspathMultiReleaseJar ?

Copy link
Author

Choose a reason for hiding this comment

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

@jarthana Do you mean, why I have made this change or why this code is here at all?

IMHO it sounds logical, if this is handled in ClasspathMultiReleaseJar as it does not require to have duplicate code.
(But I'm really not the expert to do such refactoring in this project)

Copy link
Member

Choose a reason for hiding this comment

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

I was just wondering about having this in the super class ClasspathJar but in case of the compiler.batch package, you have made it in the subclass ClasspathMultiReleaseJar. Haven't looked at the code in detail, but IIRC, we had similar code and hierarchy in both the compiler.batch and core.builder packages.

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 this pull request may close these issues.

5 participants