Fix TypeReference#getName for CGLIB proxies
This commit makes sure that the double '$' sign typically used by generated cglib proxies are not used as an inner class separator. Closes gh-29252
This commit is contained in:
parent
9820e3341d
commit
f2e9d112b1
|
|
@ -49,7 +49,7 @@ final class SimpleTypeReference extends AbstractTypeReference {
|
|||
if (!className.contains("$")) {
|
||||
return createTypeReference(className);
|
||||
}
|
||||
String[] elements = className.split("\\$");
|
||||
String[] elements = className.split("(?<!\\$)\\$(?!\\$)");
|
||||
SimpleTypeReference typeReference = createTypeReference(elements[0]);
|
||||
for (int i = 1; i < elements.length; i++) {
|
||||
typeReference = new SimpleTypeReference(typeReference.getPackageName(), elements[i], typeReference);
|
||||
|
|
|
|||
|
|
@ -73,6 +73,23 @@ class GeneratedTypeReferenceTests {
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void nameOfCglibProxy() {
|
||||
TypeReference reference = GeneratedTypeReference.of(
|
||||
ClassName.get("com.example", "Test$$SpringCGLIB$$0"));
|
||||
assertThat(reference.getSimpleName()).isEqualTo("Test$$SpringCGLIB$$0");
|
||||
assertThat(reference.getEnclosingType()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void nameOfNestedCglibProxy() {
|
||||
TypeReference reference = GeneratedTypeReference.of(
|
||||
ClassName.get("com.example", "Test").nestedClass("Another$$SpringCGLIB$$0"));
|
||||
assertThat(reference.getSimpleName()).isEqualTo("Another$$SpringCGLIB$$0");
|
||||
assertThat(reference.getEnclosingType()).isNotNull();
|
||||
assertThat(reference.getEnclosingType().getSimpleName()).isEqualTo("Test");
|
||||
}
|
||||
|
||||
@Test
|
||||
void equalsWithIdenticalCanonicalNameIsTrue() {
|
||||
assertThat(GeneratedTypeReference.of(ClassName.get("java.lang", "String")))
|
||||
|
|
|
|||
|
|
@ -76,6 +76,21 @@ class SimpleTypeReferenceTests {
|
|||
Arguments.of(SimpleTypeReference.of("com.example.Test[]"), "com.example.Test[]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void nameOfCglibProxy() {
|
||||
TypeReference reference = TypeReference.of("com.example.Test$$SpringCGLIB$$0");
|
||||
assertThat(reference.getSimpleName()).isEqualTo("Test$$SpringCGLIB$$0");
|
||||
assertThat(reference.getEnclosingType()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void nameOfNestedCglibProxy() {
|
||||
TypeReference reference = TypeReference.of("com.example.Test$Another$$SpringCGLIB$$0");
|
||||
assertThat(reference.getSimpleName()).isEqualTo("Another$$SpringCGLIB$$0");
|
||||
assertThat(reference.getEnclosingType()).isNotNull();
|
||||
assertThat(reference.getEnclosingType().getSimpleName()).isEqualTo("Test");
|
||||
}
|
||||
|
||||
@Test
|
||||
void typeReferenceInRootPackage() {
|
||||
TypeReference type = SimpleTypeReference.of("MyRootClass");
|
||||
|
|
|
|||
Loading…
Reference in New Issue