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 an exception when creating bean info for enums #2990

Closed
klaasdellschaft opened this issue Nov 27, 2023 · 4 comments
Assignees
Labels
type: bug A general bug

Comments

@klaasdellschaft
Copy link

Hi,

when upgrading my project from Spring Boot 3.1.x to 3.2.0 (and thus from Spring Beans 6.0.x / Spring Data Commons 3.1.x), I get an exception during runtime when the KotlinBeanInfoFactory tries to return the bean info for a Kotlin enum type. The following code can be used for reproducing the problem:

enum class SomeEnum(val someProperty: String) {
	VALUE_1("someValue1"),
	VALUE_2("someValue2")
}

@Test
fun determinesEnumProperties() {
    val pds = org.springframework.beans.BeanUtils.getPropertyDescriptors(SomeEnum::class.java)
    assertThat(pds).extracting("name").contains("someProperty")
}

This produces the following exception:

kotlin.reflect.jvm.internal.KotlinReflectionInternalError: No accessor found for property val entries: kotlin.enums.EnumEntries<org.springframework.data.util.KotlinBeanInfoFactoryUnitTests.SomeEnum>

	at kotlin.reflect.jvm.internal.KPropertyImplKt.computeCallerForAccessor(KPropertyImpl.kt:314)
	at kotlin.reflect.jvm.internal.KPropertyImplKt.access$computeCallerForAccessor(KPropertyImpl.kt:1)
	at kotlin.reflect.jvm.internal.KPropertyImpl$Getter$caller$2.invoke(KPropertyImpl.kt:180)
	at kotlin.reflect.jvm.internal.KPropertyImpl$Getter$caller$2.invoke(KPropertyImpl.kt:179)
	at kotlin.SafePublicationLazyImpl.getValue(LazyJVM.kt:107)
	at kotlin.reflect.jvm.internal.KPropertyImpl$Getter.getCaller(KPropertyImpl.kt:179)
	at kotlin.reflect.jvm.ReflectJvmMapping.getJavaMethod(ReflectJvmMapping.kt:64)
	at kotlin.reflect.jvm.ReflectJvmMapping.getJavaGetter(ReflectJvmMapping.kt:49)
	at org.springframework.data.util.KotlinBeanInfoFactory.getBeanInfo(KotlinBeanInfoFactory.java:67)
	at org.springframework.beans.CachedIntrospectionResults.getBeanInfo(CachedIntrospectionResults.java:222)
	at org.springframework.beans.CachedIntrospectionResults.<init>(CachedIntrospectionResults.java:248)
	at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:157)
	at org.springframework.beans.BeanUtils.getPropertyDescriptors(BeanUtils.java:490)

This problem is potentially similar to #2964

In the above test, I'm not sure which other properties should be asserted (in addition to someProperty). Checking with previous behavior in Spring Beans 6.0.x (from which BeanUtils is coming from) / Spring Data Commons 3.1.x, the following properties had previously been detected for the SomeEnum class: class, declaringClass, entries, someProperty, name, ordinal.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 27, 2023
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 27, 2023
@mp911de mp911de self-assigned this Nov 27, 2023
quaff added a commit to quaff/spring-data-commons that referenced this issue Nov 29, 2023
@mp911de
Copy link
Member

mp911de commented Nov 29, 2023

It makes sense for us to backoff for enums. We do not want to determine properties for enums as we treat enums as values. class, declaringClass, entries and other properties are determined by the simple bean info factory.

mp911de added a commit that referenced this issue Nov 29, 2023
We now no longer contribute properties for enum types.

Closes #2990
@mp911de mp911de added this to the 3.2.1 (2023.1.1) milestone Nov 29, 2023
@mp911de
Copy link
Member

mp911de commented Nov 29, 2023

That's fixed now. Do you want to give the latest 3.2.1 snapshots (3.2.1-SNAPSHOT) a try?

@klaasdellschaft
Copy link
Author

Hi @mp911de thanks for the quick fix of the problem. I gave 3.2.1-SNAPSHOT a try in my application. It was successful, so I would consider it fixed for now.

@mp911de
Copy link
Member

mp911de commented Nov 29, 2023

Thanks for checking out the fix. It's going to be available with the next service release mid-December, see https://calendar.spring.io/.

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

Successfully merging a pull request may close this issue.

3 participants