Module name check is too restrictive

harold seigel harold.seigel at oracle.com
Mon Aug 29 18:08:29 UTC 2016


Hi Remi,

Thanks for pointing this out.  We have entered bug 
https://bugs.openjdk.java.net/browse/JDK-8164969 for this issue.

Harold


On 8/28/2016 3:31 PM, Remi Forax wrote:
> While testing ASM,
> i've found that you can not currently load a module that has a '+' in its name.
>
> /usr/jdk/jdk-9-jigsaw/bin/java --module-path tmp --module "foo+bar"
> Error occurred during initialization of VM
> java.lang.module.ResolutionException: Error reading module: tmp/foo
> 	at java.lang.module.Resolver.findWithBeforeFinder(java.base at 9-ea/Resolver.java:735)
> 	at java.lang.module.Resolver.resolveRequires(java.base at 9-ea/Resolver.java:86)
> 	at java.lang.module.Configuration.resolveRequiresAndUses(java.base at 9-ea/Configuration.java:370)
> 	at java.lang.module.ModuleDescriptor$1.resolveRequiresAndUses(java.base at 9-ea/ModuleDescriptor.java:2081)
> 	at jdk.internal.module.ModuleBootstrap.boot(java.base at 9-ea/ModuleBootstrap.java:263)
> 	at java.lang.System.initPhase2(java.base at 9-ea/System.java:1927)
> Caused by: java.lang.module.InvalidModuleDescriptorException: foo+bar: Invalid module name:  Illegal character at index 3
> 	at java.lang.module.ModuleInfo.invalidModuleDescriptor(java.base at 9-ea/ModuleInfo.java:804)
> 	at java.lang.module.ModuleInfo.read(java.base at 9-ea/ModuleInfo.java:92)
> 	at java.lang.module.ModuleDescriptor.read(java.base at 9-ea/ModuleDescriptor.java:1902)
> 	at java.lang.module.ModulePath.readExplodedModule(java.base at 9-ea/ModulePath.java:591)
> 	at java.lang.module.ModulePath.readModule(java.base at 9-ea/ModulePath.java:268)
> 	at java.lang.module.ModulePath.scanDirectory(java.base at 9-ea/ModulePath.java:234)
> 	at java.lang.module.ModulePath.scan(java.base at 9-ea/ModulePath.java:188)
> 	at java.lang.module.ModulePath.scanNextEntry(java.base at 9-ea/ModulePath.java:145)
> 	at java.lang.module.ModulePath.find(java.base at 9-ea/ModulePath.java:109)
> 	at java.lang.module.ModuleFinder$2.lambda$find$0(java.base at 9-ea/ModuleFinder.java:359)
> 	at java.util.stream.ReferencePipeline$3$1.accept(java.base at 9-ea/ReferencePipeline.java:195)
> 	at java.util.Spliterators$ArraySpliterator.tryAdvance(java.base at 9-ea/Spliterators.java:958)
> 	at java.util.stream.ReferencePipeline.forEachWithCancel(java.base at 9-ea/ReferencePipeline.java:127)
> 	at java.util.stream.AbstractPipeline.copyIntoWithCancel(java.base at 9-ea/AbstractPipeline.java:502)
> 	at java.util.stream.AbstractPipeline.copyInto(java.base at 9-ea/AbstractPipeline.java:488)
> 	at java.util.stream.AbstractPipeline.wrapAndCopyInto(java.base at 9-ea/AbstractPipeline.java:474)
> 	at java.util.stream.FindOps$FindOp.evaluateSequential(java.base at 9-ea/FindOps.java:152)
> 	at java.util.stream.AbstractPipeline.evaluate(java.base at 9-ea/AbstractPipeline.java:234)
> 	at java.util.stream.ReferencePipeline.findFirst(java.base at 9-ea/ReferencePipeline.java:476)
> 	at java.lang.module.ModuleFinder$2.find(java.base at 9-ea/ModuleFinder.java:361)
> 	at java.lang.module.Resolver.findWithBeforeFinder(java.base at 9-ea/Resolver.java:732)
> 	at java.lang.module.Resolver.resolveRequires(java.base at 9-ea/Resolver.java:86)
> 	at java.lang.module.Configuration.resolveRequiresAndUses(java.base at 9-ea/Configuration.java:370)
> 	at java.lang.module.ModuleDescriptor$1.resolveRequiresAndUses(java.base at 9-ea/ModuleDescriptor.java:2081)
> 	at jdk.internal.module.ModuleBootstrap.boot(java.base at 9-ea/ModuleBootstrap.java:263)
> 	at java.lang.System.initPhase2(java.base at 9-ea/System.java:1927)
>
> According to the spec [1] section 2.1, the module name is a name in its internal form (JVMS 4.2.1)
> so it's a sequence of unicode characters (beside '.', ';', '[' and '/') separated by '/'.
> So '+' is a valid character.
>
> The code that checks the name of a module is in jdk.internal.module.Checks::requireModuleName and it checks that the name is a valid Java identifier which is obviously wrong.
> The module name of a module-info.java is a java identifier because it is parsed by javac but a module name in a module-info.class is encoded a binary name to not add restrictions to module names defined by other languages than Java.
>
> There is also a pending spec issue [2] to make a module name a unicode sequence of any characters and not a binary name removing the restriction around the characters ('.', ';', '[').
> For '/', it's a little different because if a module name allows '/', the encoding of the option '--module' of the java executable becomes ambiguous.
>
> regards,
> Rémi
>
> [1] http://cr.openjdk.java.net/~mr/jigsaw/spec/lang-vm.html
> [2] http://openjdk.java.net/projects/jigsaw/spec/issues/#ClassFileModuleName



More information about the jigsaw-dev mailing list