Skip to content

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

@jbb01

Description

@jbb01

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.

Metadata

Metadata

Assignees

Labels

acceptedThe issue/enhancement is valid, sensible, and explained in sufficient detailbugjavac

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions