Skip to content

Commit d83dd7e

Browse files
committed
Un-mangle Kotlin method names in PartTree.
Due to shortcomings with value classes mangling and the impossible usage of JvmName on Kotlin interfaces, we're inspecting now the method name if it contains a dash (-). If so, then we truncate the method name to be able to parse it. Closes #2965
1 parent f060bcf commit d83dd7e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/main/java/org/springframework/data/repository/query/parser/PartTree.java

+6
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ public PartTree(String source, Class<?> domainClass) {
8787
Assert.notNull(source, "Source must not be null");
8888
Assert.notNull(domainClass, "Domain class must not be null");
8989

90+
// Kotlin name mangling, @JvmName cannot be used with interfaces
91+
int dash = source.indexOf('-');
92+
if (dash > -1) {
93+
source = source.substring(0, dash);
94+
}
95+
9096
Matcher matcher = PREFIX_TEMPLATE.matcher(source);
9197

9298
if (!matcher.find()) {

src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.List;
2828

2929
import org.junit.jupiter.api.Test;
30-
3130
import org.springframework.data.domain.Limit;
3231
import org.springframework.data.domain.Sort;
3332
import org.springframework.data.mapping.PropertyPath;
@@ -657,6 +656,14 @@ void allCapsInOrderBy() {
657656
assertThat(tree.getSort()).hasSize(1);
658657
}
659658

659+
@Test // GH-2965
660+
void unmangleKotlinMethodName() {
661+
662+
var tree = new PartTree("findById-u1QWhUI", Order.class);
663+
664+
assertThat(tree.getParts()).hasSize(1);
665+
}
666+
660667
private static void assertLimiting(String methodName, Class<?> entityType, boolean limiting, Integer maxResults) {
661668
assertLimiting(methodName, entityType, limiting, maxResults, false);
662669
}

0 commit comments

Comments
 (0)