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

KotlinBeanInfoFactory throws IntrospectionException when the setter doesn't match getter type #3167

Closed
ldwqh0 opened this issue Sep 28, 2024 · 0 comments
Assignees
Labels
type: bug A general bug

Comments

@ldwqh0
Copy link

ldwqh0 commented Sep 28, 2024

with Spring boot 3.3.4

There is a simple entity class like this
User.kt

import jakarta.persistence.Entity
import org.springframework.data.jpa.domain.AbstractAuditable

@Entity
class User : AbstractAuditable<User, Long>() {
    var name: String? = null
}

and a simple repository like this
UserRepository.kt

import org.springframework.data.jpa.repository.JpaRepository

interface UserRepository : JpaRepository<User, Long>

a boot class like this
DemoApplication.kt

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication

@SpringBootApplication
class DemoApplication

fun main(args: Array<String>) {
    runApplication<DemoApplication>(*args)
}

whe I run the DemoApplication ,then throw exception

Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository' defined in com.xzcode.demo.UserRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Failed to obtain BeanInfo for class [com.xzcode.demo.User]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1806) ~[spring-beans-6.1.13.jar:6.1.13]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:600) ~[spring-beans-6.1.13.jar:6.1.13]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) ~[spring-beans-6.1.13.jar:6.1.13]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337) ~[spring-beans-6.1.13.jar:6.1.13]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.13.jar:6.1.13]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335) ~[spring-beans-6.1.13.jar:6.1.13]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.1.13.jar:6.1.13]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:969) ~[spring-beans-6.1.13.jar:6.1.13]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:971) ~[spring-context-6.1.13.jar:6.1.13]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:625) ~[spring-context-6.1.13.jar:6.1.13]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.3.4.jar:3.3.4]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-3.3.4.jar:3.3.4]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) ~[spring-boot-3.3.4.jar:3.3.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:335) ~[spring-boot-3.3.4.jar:3.3.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) ~[spring-boot-3.3.4.jar:3.3.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352) ~[spring-boot-3.3.4.jar:3.3.4]
	at com.xzcode.demo.DemoApplicationKt.main(DemoApplication.kt:13) ~[main/:na]
Caused by: org.springframework.data.mapping.MappingException: Failed to obtain BeanInfo for class [com.xzcode.demo.User]
	at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:427) ~[spring-data-commons-3.3.4.jar:3.3.4]
	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:320) ~[spring-data-commons-3.3.4.jar:3.3.4]
	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:246) ~[spring-data-commons-3.3.4.jar:3.3.4]
	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:97) ~[spring-data-commons-3.3.4.jar:3.3.4]
	at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$6(RepositoryFactoryBeanSupport.java:289) ~[spring-data-commons-3.3.4.jar:3.3.4]
	at java.base/java.util.Optional.ifPresent(Optional.java:178) ~[na:na]
	at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:289) ~[spring-data-commons-3.3.4.jar:3.3.4]
	at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:132) ~[spring-data-jpa-3.3.4.jar:3.3.4]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853) ~[spring-beans-6.1.13.jar:6.1.13]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1802) ~[spring-beans-6.1.13.jar:6.1.13]
	... 16 common frames omitted
Caused by: org.springframework.beans.FatalBeanException: Failed to obtain BeanInfo for class [com.xzcode.demo.User]
	at org.springframework.beans.CachedIntrospectionResults.<init>(CachedIntrospectionResults.java:301) ~[spring-beans-6.1.13.jar:6.1.13]
	at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:157) ~[spring-beans-6.1.13.jar:6.1.13]
	at org.springframework.beans.BeanUtils.getPropertyDescriptors(BeanUtils.java:488) ~[spring-beans-6.1.13.jar:6.1.13]
	at org.springframework.data.mapping.context.AbstractMappingContext.doAddPersistentEntity(AbstractMappingContext.java:463) ~[spring-data-commons-3.3.4.jar:3.3.4]
	at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:424) ~[spring-data-commons-3.3.4.jar:3.3.4]
	... 25 common frames omitted
Caused by: java.beans.IntrospectionException: type mismatch between read and write methods
	at java.desktop/java.beans.PropertyDescriptor.findPropertyType(PropertyDescriptor.java:699) ~[na:na]
	at java.desktop/java.beans.PropertyDescriptor.setWriteMethod(PropertyDescriptor.java:356) ~[na:na]
	at java.desktop/java.beans.PropertyDescriptor.<init>(PropertyDescriptor.java:142) ~[na:na]
	at org.springframework.data.util.KotlinBeanInfoFactory.getBeanInfo(KotlinBeanInfoFactory.java:116) ~[spring-data-commons-3.3.4.jar:3.3.4]
	at org.springframework.beans.CachedIntrospectionResults.getBeanInfo(CachedIntrospectionResults.java:222) ~[spring-beans-6.1.13.jar:6.1.13]
	at org.springframework.beans.CachedIntrospectionResults.<init>(CachedIntrospectionResults.java:248) ~[spring-beans-6.1.13.jar:6.1.13]
	... 29 common frames omitted

But I change the code to java. there is no problem. it can be run success.

User.java

import jakarta.persistence.Entity;
import org.springframework.data.jpa.domain.AbstractAuditable;

@Entity
public class User extends AbstractAuditable<User, Long> {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

UserRepository.java

import com.xzcode.demo.model.User;
import org.springframework.data.jpa.repository.JpaRepository;

public interface UserRepository extends JpaRepository<User, Long> {
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 28, 2024
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 30, 2024
@mp911de mp911de changed the title KotlinBeanInfoFactory throw java.beans.IntrospectionException when the setter is simple type and getter is Optional type KotlinBeanInfoFactory throws IntrospectionException when the setter doesn't match getter type Sep 30, 2024
@mp911de mp911de self-assigned this Sep 30, 2024
mp911de added a commit that referenced this issue Sep 30, 2024
mp911de added a commit that referenced this issue Sep 30, 2024
mp911de added a commit that referenced this issue Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants