-
Bug
-
Resolution: Unresolved
-
P4
-
9, 11.0.8
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
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