Skip to content

Commit bead289

Browse files
committed
DATACMNS-1079 - Polishing.
Refactored all the checks done to check if ClassGeneratingProperty works into separate methods, so the body of isSupported becomes nice and readable.
1 parent 49de635 commit bead289

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/main/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactory.java

+19-8
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,12 @@ public boolean isSupported(PersistentEntity<?, ?> entity) {
101101

102102
Assert.notNull(entity, "PersistentEntity must not be null!");
103103

104-
try {
105-
Evil.getClassLoaderMethod(entity);
106-
} catch (Exception o_O) {
107-
return false;
108-
}
104+
return isClassLoaderDefineClassAccessible(entity) //
105+
&& isTypeInjectable(entity) //
106+
&& arePropertyHashCodesUnique(entity);
107+
}
109108

110-
if (entity.getType().getClassLoader() == null || entity.getType().getPackage().getName().startsWith("java")) {
111-
return false;
112-
}
109+
private boolean arePropertyHashCodesUnique(PersistentEntity<?, ?> entity) {
113110

114111
final Set<Integer> hashCodes = new HashSet<>();
115112
final AtomicInteger propertyCount = new AtomicInteger();
@@ -132,6 +129,20 @@ public boolean isSupported(PersistentEntity<?, ?> entity) {
132129
return hashCodes.size() == propertyCount.get();
133130
}
134131

132+
private static boolean isTypeInjectable(PersistentEntity<?, ?> entity) {
133+
return entity.getType().getClassLoader() != null && !entity.getType().getPackage().getName().startsWith("java");
134+
}
135+
136+
private static boolean isClassLoaderDefineClassAccessible(PersistentEntity<?, ?> entity) {
137+
138+
try {
139+
Evil.getClassLoaderMethod(entity);
140+
} catch (Exception o_O) {
141+
return false;
142+
}
143+
return true;
144+
}
145+
135146
/**
136147
* @param entity must not be {@literal null}.
137148
* @return

0 commit comments

Comments
 (0)