Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeanWrapperImpl NPE in setWrappedInstance after invoking getPropertyValue #29681

Closed
Jiechang783 opened this issue Dec 13, 2022 · 0 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: regression A bug that is also a regression
Milestone

Comments

@Jiechang783
Copy link

  • Java 17
  • Spring boot 3.0.0

I was trying to invoke setWrappedInstance to set a new object on BeanWrapperImpl, but I got NullPointerException after invoking getPropertyValue.

Below is how I reproduce this issue:
LightSaber, Person, Jedi define:

public interface LightSaber {
    void getLightSaber();
}
import lombok.Data;

@Data
public class Person implements LightSaber {
    private String firstName;
    private String lastName;

    @Override
    public void getLightSaber() {
        System.out.println("get light saber");
    }
}
import lombok.Data;

@Data
public class Jedi extends Person {
}

My test code:

    @Test
    void setBeanWrapperInstance_mockSetInstanceTwice() {
        BeanWrapperImpl beanWrapper = new BeanWrapperImpl(Jedi.class);

        LightSaber luke = new Jedi(){{setFirstName("Luke"); setLastName("Skywalker");}};
        beanWrapper.setWrappedInstance(luke);
        Assertions.assertEquals("Luke", beanWrapper.getPropertyValue("firstName"));

        LightSaber anakin = new Jedi(){{setFirstName("Anakin"); setLastName("Skywalker");}};
        beanWrapper.setWrappedInstance(anakin);

        Assertions.assertEquals("Anakin", beanWrapper.getPropertyValue("firstName"));
    }

Error Output:

java.lang.NullPointerException: Cannot invoke "java.beans.BeanDescriptor.getBeanClass()" because the return value of "java.beans.BeanInfo.getBeanDescriptor()" is null

                at org.springframework.beans.CachedIntrospectionResults.getBeanClass(CachedIntrospectionResults.java:383)
                at org.springframework.beans.BeanWrapperImpl.setIntrospectionClass(BeanWrapperImpl.java:151)
                at org.springframework.beans.BeanWrapperImpl.setWrappedInstance(BeanWrapperImpl.java:142)
                at org.springframework.beans.AbstractNestablePropertyAccessor.setWrappedInstance(AbstractNestablePropertyAccessor.java:184)
                at com.jiechang.demo.service.BeanWrapperImplTest.setBeanWrapperInstance_mockSetInstanceTwice(BeanWrapperImplTest.java:19)
                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
                at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.base/java.lang.reflect.Method.invoke(Method.java:568)
                at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
                at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
                at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
                at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
...
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 13, 2022
@jhoeller jhoeller self-assigned this Dec 13, 2022
@jhoeller jhoeller added type: regression A bug that is also a regression in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 13, 2022
@jhoeller jhoeller added this to the 6.0.3 milestone Dec 13, 2022
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.3.x labels Dec 13, 2022
@jhoeller jhoeller changed the title BeanWrapperImpl NPE when invoke setWrappedInstance after invoking getPropertyValue BeanWrapperImpl NPE in setWrappedInstance after invoking getPropertyValue Dec 13, 2022
jhoeller added a commit that referenced this issue Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

3 participants