Modules with packages duplication

Konstantin Barzilovich konstantin.barzilovich at oracle.com
Thu May 5 15:21:20 UTC 2016


Hello Alan,

Thank you for the answer.

I have one more question connected with duplication of packages.
Now we can compile two modules with the duplicated package without  
compile-time error if there is no module which can access both of them.
But in case of these two modules are readable by third module, in runtime  
it will result in error of boot Layer, as you said.
Is it okey, that compiler allow us to compile code, that will cause  
runtime failure?

Here is minimal test case:
------------------------------
module1/module-info.java
module module1 {
     exports pack;
}

module1/pack/A.java:
package pack;
public class A{}

module2/module-info.java
module module2 {
}

module2/pack/A.java:
package pack;
public class A{}

module3/module-info.java:
module module3{
     requires module1;
     requires module2;
}

Thanks,
Konstantin.

>
> On 04/05/2016 14:18, Konstantin Barzilovich wrote:
>> Hello,
>>
>> I can see that RI checks if there are packages with the same names in  
>> different modules (named or unnamed).
>> This check fails even if there is no clash (no module can read both  
>> packages).
>> Will it be the same in final version of JDK9 or it can be changed soon?
>>
> I think you are asking about modules on the application module path  
> (`java -modulepath ...`) that are resolved at startup. These are defined  
> to the application class loader so they cannot have overlapping  
> packages. It's trivial to do things like map each module in its own  
> class loader but that messes with visibility with lots of implications  
> (particularly when running with both a class path and module path or  
> where you bringing automatic modules into the picture). So what you are  
> seeing is specific to the boot Layer and no specific short term plans to  
> change this.
>
> -Alan


More information about the jigsaw-dev mailing list