Skip to content

KotlinBeanInfoFactory fails on bean where setter is primitive type and getter is boxed #2993

Closed
@drewhk

Description

@drewhk

I have a bean that worked before (spring-boot 3.1.3 and Kotlin 1.7.21), but does not work with 3.2.0 (and Kotlin 1.9.21).

The following code reproduces this issue (edited down to only show relevant parts):

typealias Timestamp = Long

interface Interval<T : Comparable<T>> : Comparable<Interval<T>> {
    val end: T
    // ...
}

abstract class MyEntity: Interval<Timestamp> {
  //...
  override var end: Timestamp = -1L
      protected set
  //...
}

The end property above compiles down to the following pair of getter and setter (taken from javap output):

  public java.lang.Long getEnd();
    descriptor: ()Ljava/lang/Long;

  protected void setEnd(long);
    descriptor: (J)V

So this ends up in KotlinBeanInfoFactory as a call to pds.add(new PropertyDescriptor(property.getName(), getter, setter));. At this point the getter is public java.lang.Long MyEntity.getEnd() and the setter is protected void MyEntity.setEnd(long). This call finally ends up in java.beans.PropertyDescriptor.findPropertyType@L678, where the test if (propertyType != null && !params[0].isAssignableFrom(propertyType)) fails with a IntrospectionException("type mismatch between read and write methods"). The reason is that isAssignableFrom fails on comparing long and java.lang.Long.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions