Unexpected ClassnotFoundException on reflective Class#getMethod

Dawid Weiss dawid.weiss at gmail.com
Thu Apr 7 11:25:05 UTC 2016


> I'm curious what the following lists for you:
>
>   java
> -Xpatch:java.annotations.common=mods/javax.annotation.priority at 1.0.jar
> -listmods:java.annotations.common

I noticed that patch JARs cannot have module-infos so a plain jar file
with javax.annotation.Priority annotation inside would print:

> java -Xpatch:java.annotations.common=mods/javax.annotation.priority at 1.0.jar -listmods:java.annotations.common
java.annotations.common at 9-ea
  requires mandated java.base
  exports javax.annotation

And this works as expected, that is the Priority class is found properly:

> java -Xpatch:java.annotations.common=mods/javax.annotation.priority at 1.0.jar -cp . Test
Hello: interface javax.annotation.Priority

Let me reorder your e-mail a bit here:

> In any case, the right way to deploy with the upgraded version is:
>
>    -upgrademodulepath mods/javax.annotation at 1.2.jar
>
> where the JAR file has a compiled module declaration to declare the module,
> its dependences, and exports.

I did create the module info, but I failed to recognize the fact that
the name of the module needs to be identical to the one it upgrades
(rather than just cover the exported package). My bad, rookie mistake.

module javax.annotation.priority {
        exports javax.annotation;
}

Tried again, it works. By the way -- jar's help says upgrademodulepath
are directories, it's useful to know they can be exact file pointers
too.

    -upgrademodulepath <module path>...
                  A ; separated list of directories, each directory
                  is a directory of modules that replace upgradeable
                  modules in the runtime image

> Hacking the packaged modules will fall foul of integrity checks. This
> suggests to me that you didn't actually create or compile a
> module-info.java.

I did. But I also wanted some sanity check so I opened
java.annotations.common.jmod and copied everything from classes/* to
another zip file (java.annotations.common.jar). I notice there are sha
checksums inside module-info.class, but these files are identical and
they still produce the same error:

Error occurred during initialization of VM
java.lang.module.ResolutionException: Unable to compute the hash of
module java.base

Probably the hashes are computed based on something else than file
content alone (?). Thanks for help, Alan. I think I have a better
understanding of how it all fits together now.

Dawid


More information about the jigsaw-dev mailing list