-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
20
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
jdk.internal.module.ModulePath.deriveDescriptor() fails to derive a module name based on certain file name patters. This method is internal API consumed by ModuleFinder.findAll() which is public API.
The following filenames derive the module name as `foo`:
* foo-1.jar
* foo-1.0.jar
* foo-1.0-TAG.jar
The following filenames will create invalid module names:
* foo-1-TAG.jar
* foo-1+BUILD.jar // java module, java runtime
* foo-2023_1.jar // calver
https://docs.oracle.com/javase/9/docs/api/java/lang/module/ModuleDescriptor.Version.html
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Runtime.Version.html
https://calver.org/
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. create 4 jars with the following names
* foo-1.0-TAG.jar
* foo-1-TAG.jar
* foo-1+BUILD.jar
* foo-2023_1.jar
2. Minimum code to trigger errors
```
import java.lang.module.ModuleFinder;
import java.nio.file.Paths;
println ModuleFinder.of(Paths.get("foo-1.0-TAG.jar")).findAll();
println ModuleFinder.of(Paths.get("foo-1-TAG.jar")).findAll();
println ModuleFinder.of(Paths.get("foo-1+BUILD.jar")).findAll();
println ModuleFinder.of(Paths.get("foo-2023_1.jar")).findAll();
```
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
4 successful modules named `foo` found with output similar to
```
[[module foo, location=file:///private/tmp/foo-1.0-TAG.jar]]
[[module foo, location=file:///private/tmp/foo-1-TAG.jar]]
[[module foo, location=file:///private/tmp/foo-1+BUILD.jar]]
[[module foo, location=file:///private/tmp/foo-2023_1.jar]]
```
ACTUAL -
Exceptions for JARs 2, 3, and 4. Similar to
```
java.lang.module.FindException: Unable to derive module descriptor for foo-1-TAG.jar
at java.base/jdk.internal.module.ModulePath.readJar(ModulePath.java:648)
at java.base/jdk.internal.module.ModulePath.readModule(ModulePath.java:331)
at java.base/jdk.internal.module.ModulePath.scan(ModulePath.java:237)
at java.base/jdk.internal.module.ModulePath.scanNextEntry(ModulePath.java:190)
at java.base/jdk.internal.module.ModulePath.findAll(ModulePath.java:166)
Caused by: java.lang.IllegalArgumentException: foo.1.TAG: Invalid module name: '1' is not a Java identifier
at java.base/jdk.internal.module.Checks.requireModuleName(Checks.java:52)
at java.base/jdk.internal.module.ModulePath.deriveModuleDescriptor(ModulePath.java:508)
at java.base/jdk.internal.module.ModulePath.readJar(ModulePath.java:644)
... 11 more
```
CUSTOMER SUBMITTED WORKAROUND :
There is no workaround
FREQUENCY : always
jdk.internal.module.ModulePath.deriveDescriptor() fails to derive a module name based on certain file name patters. This method is internal API consumed by ModuleFinder.findAll() which is public API.
The following filenames derive the module name as `foo`:
* foo-1.jar
* foo-1.0.jar
* foo-1.0-TAG.jar
The following filenames will create invalid module names:
* foo-1-TAG.jar
* foo-1+BUILD.jar // java module, java runtime
* foo-2023_1.jar // calver
https://docs.oracle.com/javase/9/docs/api/java/lang/module/ModuleDescriptor.Version.html
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Runtime.Version.html
https://calver.org/
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. create 4 jars with the following names
* foo-1.0-TAG.jar
* foo-1-TAG.jar
* foo-1+BUILD.jar
* foo-2023_1.jar
2. Minimum code to trigger errors
```
import java.lang.module.ModuleFinder;
import java.nio.file.Paths;
println ModuleFinder.of(Paths.get("foo-1.0-TAG.jar")).findAll();
println ModuleFinder.of(Paths.get("foo-1-TAG.jar")).findAll();
println ModuleFinder.of(Paths.get("foo-1+BUILD.jar")).findAll();
println ModuleFinder.of(Paths.get("foo-2023_1.jar")).findAll();
```
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
4 successful modules named `foo` found with output similar to
```
[[module foo, location=file:///private/tmp/foo-1.0-TAG.jar]]
[[module foo, location=file:///private/tmp/foo-1-TAG.jar]]
[[module foo, location=file:///private/tmp/foo-1+BUILD.jar]]
[[module foo, location=file:///private/tmp/foo-2023_1.jar]]
```
ACTUAL -
Exceptions for JARs 2, 3, and 4. Similar to
```
java.lang.module.FindException: Unable to derive module descriptor for foo-1-TAG.jar
at java.base/jdk.internal.module.ModulePath.readJar(ModulePath.java:648)
at java.base/jdk.internal.module.ModulePath.readModule(ModulePath.java:331)
at java.base/jdk.internal.module.ModulePath.scan(ModulePath.java:237)
at java.base/jdk.internal.module.ModulePath.scanNextEntry(ModulePath.java:190)
at java.base/jdk.internal.module.ModulePath.findAll(ModulePath.java:166)
Caused by: java.lang.IllegalArgumentException: foo.1.TAG: Invalid module name: '1' is not a Java identifier
at java.base/jdk.internal.module.Checks.requireModuleName(Checks.java:52)
at java.base/jdk.internal.module.ModulePath.deriveModuleDescriptor(ModulePath.java:508)
at java.base/jdk.internal.module.ModulePath.readJar(ModulePath.java:644)
... 11 more
```
CUSTOMER SUBMITTED WORKAROUND :
There is no workaround
FREQUENCY : always