Skip to content

Commit 7fb23cd

Browse files
Sannebeikov
authored andcommitted
HHH-18108 Avoid applying the ClassTransformer on types we will be loading
1 parent 1c1572b commit 7fb23cd

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

hibernate-core/src/main/java/org/hibernate/jpa/internal/enhance/EnhancingClassTransformerImpl.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public class EnhancingClassTransformerImpl implements ClassTransformer {
3131
private final ReentrantLock lock = new ReentrantLock();
3232
private volatile WeakReference<Entry> entryReference;
3333

34+
//This list is matching the constants used by CoreTypePool's default constructor
35+
private static final String[] NO_TRANSFORM_PREFIXES = { "jakarta/", "java/", "org/hibernate/annotations/" };
36+
3437
public EnhancingClassTransformerImpl(EnhancementContext enhancementContext) {
3538
Objects.requireNonNull( enhancementContext );
3639
this.enhancementContext = enhancementContext;
@@ -45,6 +48,16 @@ public byte[] transform(
4548
ProtectionDomain protectionDomain,
4649
byte[] classfileBuffer) throws TransformerException {
4750

51+
//Take care to not transform certain types; this is both an optimisation (we can skip this unnecessary work)
52+
//and a safety precaution as we otherwise risk attempting to redefine classes which have already been loaded:
53+
//see https://hibernate.atlassian.net/browse/HHH-18108
54+
//N.B. this className doesn't use the dot-format but the slashes for package separators.
55+
for ( String prefix : NO_TRANSFORM_PREFIXES ) {
56+
if ( className.startsWith( prefix ) ) {
57+
return null;
58+
}
59+
}
60+
4861
try {
4962
return getEnhancer( loader ).enhance( className, classfileBuffer );
5063
}

0 commit comments

Comments
 (0)