- Notifications
You must be signed in to change notification settings - Fork 38.9k
Closed
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: documentationA documentation taskA documentation task
Milestone
Description
This is issue is somewhat hard to explain. I created a small project where this issue can be demonstrated.
Given following classes:
package com.flightkeys.cglibbug.base; public class BaseClass { private final ObjectMapper mapper = new ObjectMapper(); String serialize(Object value) { return serialize(getMapper(), value); } private ObjectMapper getMapper() { return mapper; } private String serialize(ObjectMapper mapper, Object value) { return mapper.writeToString(value); } }package com.flightkeys.cglibbug.derived; import com.flightkeys.cglibbug.base.BaseClass; import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.stereotype.Component; @Component @Scope(proxyMode = ScopedProxyMode.TARGET_CLASS) public class DerivedClass extends BaseClass { }If we pass around instance of DerivedClass and on that instance BaseClass.serialize is called, then return mapper.writeToString(value); will throw null pointer exception.
It seems that CGLIB is not proxying the String serialize(Object value) method. However, if we move DerivedClass into same package or either String serialize(Object value) or private ObjectMapper getMapper() is made protected, then it works.
NOTE: We noticed this when upgrading from spring-boot 2.1.18 to 2.2.13, but it is also reproducible on 2.7.2.
tobisinghania
Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: documentationA documentation taskA documentation task