automatic modules leaking types when using addmods

Paul Benedict pbenedict at apache.org
Mon Apr 25 00:38:24 UTC 2016


Automatic modules live in a classpath-like world. Everything is exported to
each other. You use this feature if you don't have time to migrate to a
modular architecture.
On Apr 24, 2016 3:01 PM, "Paul Bakker" <paul.bakker.nl at gmail.com> wrote:

> So when modules B, C and D are automatic modules and named module A
> depends on B, A also gets implicit readability to C and D?
> What is the reasoning behind this automatic implicit readability? It makes
> migration less reliable I think, because it hides what dependencies a
> module really has.
>
> Paul
>
>
> > On 24 Apr 2016, at 21:06, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> >
> >
> > On 24/04/2016 10:57, Paul Bakker wrote:
> >> Hello,
> >>
> >> Another question related to automatic modules.
> >> I have the following code:
> >>         import com.fasterxml.jackson.core.JsonFactory;
> >>         ...
> >>      JsonFactory f = new JsonFactory();
> >>      System.out.println(f.getCodec());
> >>
> >> This code clearly depends on jackson.core. So my module-info contains:
> >>      requires jackson.core;
> >>
> >> This is as expected. I can change the module-info to the following
> however (removing the dependency on jackson.core):
> >>      requires jackson.databind;
> >>
> >> At first sight, this fails to compile as expected, because the
> JsonFactory type comes from jackson.core, not from jackson.databind.
> >> But when I add "-addmods jackson.core" to my build command, it builds
> successfully! That's not what I would expect, because my module doesn't
> declare a dependency on jackson.core. Why does this happen? I would expect
> that the -addmods adds the module to the available modules, but does not
> magically add read edges to named modules.
> >> When removing the "jackson.databind" requires in my module-info, it
> fails to compile again, so it looks like jackson.databind somehow leaks
> types from jackson.core to my module.
> >>
> >> The build command I use is the following:
> >>      javac -mp mods -addmods jackson.core -d out -modulesourcepath src
> $(find src -name '*.java')
> >>
> >>
> > Are both jackson.databind and jackson.core automatic modules in this
> scenario? I assume so, in which case I think what you are seeing is correct
> (meaning it should compile). The reason is that automatic modules read all
> other modules and they also grant implied readability to all other
> automatic modules. In this example then it is as if jackson.databind
> `requires public jackson.core` so your module will read jackson.core.
> >
> > -Alan
>
>


More information about the jigsaw-dev mailing list