Skip to content

Commit

Permalink
Don't treat Kotlin data classes as immutable
Browse files Browse the repository at this point in the history
Unlike records, Kotlin data classes are mutable and so we can't apply
the same constructor detection logic.

Fixes gh-34500
  • Loading branch information
philwebb committed Mar 15, 2023
1 parent d070ee2 commit 5d21c36
Showing 1 changed file with 1 addition and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import java.util.Arrays;
import java.util.stream.Stream;

import kotlin.jvm.JvmClassMappingKt;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.KotlinDetector;
Expand Down Expand Up @@ -106,7 +104,7 @@ static Constructors getConstructors(Class<?> type, boolean isNestedConstructorBi
MergedAnnotations[] candidateAnnotations = getAnnotations(candidates);
boolean kotlinType = isKotlinType(type);
boolean deducedBindConstructor = false;
boolean immutableType = type.isRecord() || isKotlinDataClass(type);
boolean immutableType = type.isRecord();
Constructor<?> bind = getConstructorBindingAnnotated(type, candidates, candidateAnnotations);
if (bind == null && !hasAutowiredConstructor) {
bind = deduceBindConstructor(type, candidates);
Expand Down Expand Up @@ -198,10 +196,6 @@ private static Constructor<?> deduceBindConstructor(Class<?> type, Constructor<?
return (result != null && result.getParameterCount() > 0) ? result : null;
}

private static boolean isKotlinDataClass(Class<?> type) {
return isKotlinType(type) && JvmClassMappingKt.getKotlinClass(type).isData();
}

private static boolean isKotlinType(Class<?> type) {
return KotlinDetector.isKotlinPresent() && KotlinDetector.isKotlinType(type);
}
Expand Down

0 comments on commit 5d21c36

Please sign in to comment.