Skip to content

Commit 49d7d11

Browse files
committed
Guard AotAccessorFactory against contributions of unsupported entiries.
AotAccessorFactory now checks if the entity is supported and could be contributed to avoid failures due to unsupported types. Closes #3361
1 parent a29a540 commit 49d7d11

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/main/java/org/springframework/data/aot/AotMappingContext.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ public Association<AotPersistentProperty> getAssociation() {
133133
static class AotAccessorFactory extends ClassGeneratingPropertyAccessorFactory {
134134

135135
public void initialize(PersistentEntity<?, ?> entity) {
136-
potentiallyCreateAndRegisterPersistentPropertyAccessorClass(entity);
136+
if (isSupported(entity)) {
137+
potentiallyCreateAndRegisterPersistentPropertyAccessorClass(entity);
138+
}
137139
}
138140
}
139141

src/test/java/org/springframework/data/aot/AotMappingContextUnitTests.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ void doesNotCreateEntityForJavaxReference() {
5454
assertThat(context.getPersistentEntity(javax.naming.Reference.class)).isNull();
5555
}
5656

57+
@Test // GH-3361
58+
void doesNotContributeGeneratedAccessorForUnsupportedType() {
59+
60+
assertThatNoException().isThrownBy(() -> {
61+
context.contribute(ConcretePerson.class);
62+
});
63+
}
64+
5765
static class DemoEntity {
5866

5967
@Id String id;
@@ -78,4 +86,30 @@ static class EntityWithReference {
7886
javax.naming.Reference reference;
7987
}
8088

89+
static abstract class AbstractPerson {
90+
91+
private String name;
92+
93+
public String getName() {
94+
return name;
95+
}
96+
97+
public void setName(String name) {
98+
this.name = name;
99+
}
100+
}
101+
102+
static class ConcretePerson extends AbstractPerson {
103+
104+
private String name;
105+
106+
public String getName() {
107+
return name;
108+
}
109+
110+
public void setName(String name) {
111+
this.name = name;
112+
}
113+
}
114+
81115
}

0 commit comments

Comments
 (0)