Browse Source

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
pull/2967/head
Mark Paluch 2 years ago
parent
commit
d83dd7e138
No known key found for this signature in database
GPG Key ID: 4406B84C1661DCD1
  1. 6
      src/main/java/org/springframework/data/repository/query/parser/PartTree.java
  2. 9
      src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java

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

@ -87,6 +87,12 @@ public class PartTree implements Streamable<OrPart> {
Assert.notNull(source, "Source must not be null"); Assert.notNull(source, "Source must not be null");
Assert.notNull(domainClass, "Domain class must not be null"); Assert.notNull(domainClass, "Domain class must not be null");
// Kotlin name mangling, @JvmName cannot be used with interfaces
int dash = source.indexOf('-');
if (dash > -1) {
source = source.substring(0, dash);
}
Matcher matcher = PREFIX_TEMPLATE.matcher(source); Matcher matcher = PREFIX_TEMPLATE.matcher(source);
if (!matcher.find()) { if (!matcher.find()) {

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

@ -27,7 +27,6 @@ import java.util.Date;
import java.util.List; import java.util.List;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.data.domain.Limit; import org.springframework.data.domain.Limit;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.mapping.PropertyPath; import org.springframework.data.mapping.PropertyPath;
@ -657,6 +656,14 @@ class PartTreeUnitTests {
assertThat(tree.getSort()).hasSize(1); assertThat(tree.getSort()).hasSize(1);
} }
@Test // GH-2965
void unmangleKotlinMethodName() {
var tree = new PartTree("findById-u1QWhUI", Order.class);
assertThat(tree.getParts()).hasSize(1);
}
private static void assertLimiting(String methodName, Class<?> entityType, boolean limiting, Integer maxResults) { private static void assertLimiting(String methodName, Class<?> entityType, boolean limiting, Integer maxResults) {
assertLimiting(methodName, entityType, limiting, maxResults, false); assertLimiting(methodName, entityType, limiting, maxResults, false);
} }

Loading…
Cancel
Save