Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8255854

JDK assumes the ModulePackages attribute, if present, lists all packages in the module

XMLWordPrintable

      Edited to note: This description does not correctly identify the root cause the issue. See later comments for details of the real root cause.

      An issue was observed attempting to use ServiceLoader in Apache Tomcat. Loading of a service failed due to a ClassNotFoundException because a class used *internally* by the specified service instance was not exported.

      Research identified that the ServiceLoader calls getDeclaredMethods() on the specified service and that for a method like this:

      public Type getType() {
          return new SubType();
      }

      where SubType is a sub-class of Type, getDeclaredMethods() triggers loading of both Type and SubType.

      This is demonstrated in the following reproducer:
      https://github.com/markt-asf/getDeclaredMethods

      Running TestOne with -verbose:class shows loading Type does not trigger the loading of SubType (as expected).

      Running TestTwo with -verbose:class shows calling getDeclaredMethods() on Type triggers the loading of SubType even though SubType is not part of any method signature of Type.

      This is causing problems for Tomcat's JPMS module definitions as we are having to explicitly open packages that should not be open in order for the ServiceLoader to be able to function.

      Also observed in 16ea21 and 8u265

            alanb Alan Bateman
            markt Mark Thomas
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: