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