Skip to content

Commit 5d21c36

Browse files
committed
Don't treat Kotlin data classes as immutable
Unlike records, Kotlin data classes are mutable and so we can't apply the same constructor detection logic. Fixes gh-34500
1 parent d070ee2 commit 5d21c36

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/DefaultBindConstructorProvider.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import java.util.Arrays;
2222
import java.util.stream.Stream;
2323

24-
import kotlin.jvm.JvmClassMappingKt;
25-
2624
import org.springframework.beans.BeanUtils;
2725
import org.springframework.beans.factory.annotation.Autowired;
2826
import org.springframework.core.KotlinDetector;
@@ -106,7 +104,7 @@ static Constructors getConstructors(Class<?> type, boolean isNestedConstructorBi
106104
MergedAnnotations[] candidateAnnotations = getAnnotations(candidates);
107105
boolean kotlinType = isKotlinType(type);
108106
boolean deducedBindConstructor = false;
109-
boolean immutableType = type.isRecord() || isKotlinDataClass(type);
107+
boolean immutableType = type.isRecord();
110108
Constructor<?> bind = getConstructorBindingAnnotated(type, candidates, candidateAnnotations);
111109
if (bind == null && !hasAutowiredConstructor) {
112110
bind = deduceBindConstructor(type, candidates);
@@ -198,10 +196,6 @@ private static Constructor<?> deduceBindConstructor(Class<?> type, Constructor<?
198196
return (result != null && result.getParameterCount() > 0) ? result : null;
199197
}
200198

201-
private static boolean isKotlinDataClass(Class<?> type) {
202-
return isKotlinType(type) && JvmClassMappingKt.getKotlinClass(type).isData();
203-
}
204-
205199
private static boolean isKotlinType(Class<?> type) {
206200
return KotlinDetector.isKotlinPresent() && KotlinDetector.isKotlinType(type);
207201
}

0 commit comments

Comments
 (0)