Hi

i was trying to play around latest jigsaw version in order to adapt an open 
source projet that i developed and i found the following issue.

When using a jar containing a class with no package, the modulefinder is 
failing to create its module descriptor.

It guesses that it is an automatic module (unamed), but fails with the 
following stack trace :


Exception in thread "main" java.lang.module.FindException: Unable to derive 
module descriptor for: 
D:\.m2\com\github\maven-nar\nar-maven-plugin\3.0.0\nar-maven-plugin-3.0.0.jar
    at java.lang.module.ModulePath.readJar(java.base@9-ea/ModulePath.java:538)
    at 
java.lang.module.ModulePath.readModule(java.base@9-ea/ModulePath.java:273)
    at java.lang.module.ModulePath.scan(java.base@9-ea/ModulePath.java:192)
    at 
java.lang.module.ModulePath.scanNextEntry(java.base@9-ea/ModulePath.java:144)
    at java.lang.module.ModulePath.findAll(java.base@9-ea/ModulePath.java:120)
    at test.Test.main(Test.java:46)
Caused by: java.lang.IllegalArgumentException: Empty package name
    at 
jdk.internal.module.Checks.requireJavaIdentifier(java.base@9-ea/Checks.java:70)
    at 
jdk.internal.module.Checks.requirePackageName(java.base@9-ea/Checks.java:93)
    at 
java.lang.module.ModuleDescriptor$Exports.<init>(java.base@9-ea/ModuleDescriptor.java:269)
    at 
java.lang.module.ModuleDescriptor$Exports.<init>(java.base@9-ea/ModuleDescriptor.java:266)
    at 
java.lang.module.ModuleDescriptor$Exports.<init>(java.base@9-ea/ModuleDescriptor.java:239)
    at 
java.lang.module.ModuleDescriptor$Builder.exports(java.base@9-ea/ModuleDescriptor.java:1347)
    at 
java.util.stream.ForEachOps$ForEachOp$OfRef.accept(java.base@9-ea/ForEachOps.java:184)
    at 
java.util.stream.DistinctOps$1$2.accept(java.base@9-ea/DistinctOps.java:175)
    at 
java.util.stream.ReferencePipeline$3$1.accept(java.base@9-ea/ReferencePipeline.java:195)
    at 
java.util.HashMap$KeySpliterator.forEachRemaining(java.base@9-ea/HashMap.java:1600)
    at 
java.util.stream.AbstractPipeline.copyInto(java.base@9-ea/AbstractPipeline.java:484)
    at 
java.util.stream.AbstractPipeline.wrapAndCopyInto(java.base@9-ea/AbstractPipeline.java:474)
    at 
java.util.stream.ForEachOps$ForEachOp.evaluateSequential(java.base@9-ea/ForEachOps.java:151)
    at 
java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(java.base@9-ea/ForEachOps.java:174)
    at 
java.util.stream.AbstractPipeline.evaluate(java.base@9-ea/AbstractPipeline.java:234)
    at 
java.util.stream.ReferencePipeline.forEach(java.base@9-ea/ReferencePipeline.java:430)
    at 
java.lang.module.ModulePath.deriveModuleDescriptor(java.base@9-ea/ModulePath.java:435)
    at java.lang.module.ModulePath.readJar(java.base@9-ea/ModulePath.java:534)
    ... 5 more



when looking in the class ModulePath, in the method deriveModuleDescriptor, the 
problem seems to come from the following code


// all packages are exported
        classFiles.stream()
            .map(c -> toPackageName(c))
            .distinct()
            .forEach(builder::exports);



when the class has no package, toPackageName returns "", and builder::exports 
throws an exception.

Easy fix could be to assert in the forEach before calling builder::exports



Thank you



Reply via email to