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

[BUG] Delombok fails to resolve module name of multi-release jar #3389

Open
jbb01 opened this issue Mar 30, 2023 · 1 comment · May be fixed by #3392
Open

[BUG] Delombok fails to resolve module name of multi-release jar #3389

jbb01 opened this issue Mar 30, 2023 · 1 comment · May be fixed by #3392
Assignees
Labels
accepted The issue/enhancement is valid, sensible, and explained in sufficient detail bug javac

Comments

@jbb01
Copy link

jbb01 commented Mar 30, 2023

Describe the bug

When a multi-release jar file with no module-info.class in the base version and no Automatic-Module-Name, but with a module-info.class in the version for the currently running JDK version, is present on the module path, delombok fails to correctly resolve the module name according to the included module-info.class and falls back to the jars name. If the jar is not named the same as the module this will lead to to errors during delomboking.

To Reproduce

  1. Find or create such a multi-release jar (for example org.jetbrains:annotations:24.0.1)
  2. Create the following hierarchy:
├─ src
│  ├─ org
│  │  └─ example
│  │     └─ Main.java
│  └─ module-info.java
└─ lib
   ├─ annotations.jar
   └─ lombok.jar

with Main.java

package org.example;

import lombok.Getter;

@Getter // prevents delombok from skipping this file
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

and module-info.java

module org.example {
    requires static org.jetbrains.annotations;
    requires static lombok;
}
  1. Compile with javac -d out -p lib/annotations.jar:lib/lombok.jar src/org/example/Main.java src/module-info.java. This will be successful.
  2. Now try delomboking the source files with java -jar lib/lombok.jar delombok --module-path lib/annotations.jar -d delombok src. This will produce the following error:
/path/to/src/module-info.java:2: error: module not found: org.jetbrains.annotations
    requires static org.jetbrains.annotations;
  1. Change the module-info.java to
module org.example {
    requires static annotations;
    requires static lombok;
}
  1. Try delomboking as in step 4. This time there won't be any errors.
  2. Try compiling as in step 3. This will produce the following error:
src/module-info.java:2: error: module not found: annotations
    requires static annotations;
                    ^
1 error

Expected behavior
Delombok should choose the correct version of the multi-release jar according to the current jdk version and correctly resolve the module name according the the module-info. Step 4 should not produce any errors. Step 6 should however.

Version info:

$ java --version
openjdk 19.0.1 2022-10-18
OpenJDK Runtime Environment Temurin-19.0.1+10 (build 19.0.1+10)
OpenJDK 64-Bit Server VM Temurin-19.0.1+10 (build 19.0.1+10, mixed mode, sharing)
$ java -jar lib/lombok.jar --version
v1.18.24 "Envious Ferret"

Additional context
com.sun.tools.javac.main.Main::compile uses the following code to set up the multi-release version

// init multi-release jar handling
if (fileManager.isSupportedOption(Option.MULTIRELEASE.primaryName) == 1) {
    Target target = Target.instance(context);
    List<String> list = List.of(target.multiReleaseValue());
    fileManager.handleOption(Option.MULTIRELEASE.primaryName, list.iterator());
}

defaulting to the currently running version of the jdk (overridable with the hidden option --multi-release <version>). lombok.delombok.Delombok is missing similar code resulting in a fallback to the jar file name in com.sun.tools.javac.file.Locations.ModulePathLocationHandler.ModulePathIterator::inferModuleName.

@Rawi01 Rawi01 added bug javac accepted The issue/enhancement is valid, sensible, and explained in sufficient detail labels Apr 2, 2023
@Rawi01 Rawi01 self-assigned this Apr 2, 2023
@Rawi01 Rawi01 linked a pull request Apr 2, 2023 that will close this issue
@moaxcp
Copy link

moaxcp commented Jun 24, 2024

I ran into this issue when using junixsocket. It is good to see there is a fix somewhere!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted The issue/enhancement is valid, sensible, and explained in sufficient detail bug javac
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants