Illegal reflective access by SpEL ReflectivePropertyAccessor #22242
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
This is technically a request to re-open SPR-17480 (JDK 11: Illegal reflective access by org.springframework.util.ReflectionUtils), since the problem has nothing to do with Thymeleaf.
Problem can be reproduced using Java 11.0.1 and Spring Expression 5.1.3.RELEASE with the following code:
Running with
--illegal-access=debug
produces the following output:The code in SPR-17480 tries to access
java.util.HashMap$Node.getKey()
, while the code above tries to accessjava.util.KeyValueHolder.getKey()
, simply because a differentMap
implementation is used. The issue is the same.The problem is that although the value returned by
getEntry()
is an interface with public methods (Map.Entry
), the real object returned is a non-public class implementing the interface. Since theReflectivePropertyAccessor
logic resolves to the method of the non-public class, not to the method of the interface,ReflectionUtils.makeAccessible(Method method)
ends up callingmethod.setAccessible(true)
.Possible solution: Enhance
ReflectivePropertyAccessor
to search for the accessor method in public interfaces and public (super-)classes. Default to current logic if method cannot be located in a public type.The text was updated successfully, but these errors were encountered: