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

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

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 9, 11.0.8
    • Fix Version/s: tbd
    • Component/s: core-libs

      Description

      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

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated: