HHH-18108 Avoid applying the ClassTransformer on types we will be loading
This commit is contained in:
parent
8878a19161
commit
5a052bafc9
|
@ -31,6 +31,9 @@ public class EnhancingClassTransformerImpl implements ClassTransformer {
|
||||||
private final ReentrantLock lock = new ReentrantLock();
|
private final ReentrantLock lock = new ReentrantLock();
|
||||||
private volatile WeakReference<Entry> entryReference;
|
private volatile WeakReference<Entry> entryReference;
|
||||||
|
|
||||||
|
//This list is matching the constants used by CoreTypePool's default constructor
|
||||||
|
private static final String[] NO_TRANSFORM_PREFIXES = { "jakarta/", "java/", "org/hibernate/annotations/" };
|
||||||
|
|
||||||
public EnhancingClassTransformerImpl(EnhancementContext enhancementContext) {
|
public EnhancingClassTransformerImpl(EnhancementContext enhancementContext) {
|
||||||
Objects.requireNonNull( enhancementContext );
|
Objects.requireNonNull( enhancementContext );
|
||||||
this.enhancementContext = enhancementContext;
|
this.enhancementContext = enhancementContext;
|
||||||
|
@ -45,6 +48,16 @@ public class EnhancingClassTransformerImpl implements ClassTransformer {
|
||||||
ProtectionDomain protectionDomain,
|
ProtectionDomain protectionDomain,
|
||||||
byte[] classfileBuffer) throws TransformerException {
|
byte[] classfileBuffer) throws TransformerException {
|
||||||
|
|
||||||
|
//Take care to not transform certain types; this is both an optimisation (we can skip this unnecessary work)
|
||||||
|
//and a safety precaution as we otherwise risk attempting to redefine classes which have already been loaded:
|
||||||
|
//see https://hibernate.atlassian.net/browse/HHH-18108
|
||||||
|
//N.B. this className doesn't use the dot-format but the slashes for package separators.
|
||||||
|
for ( String prefix : NO_TRANSFORM_PREFIXES ) {
|
||||||
|
if ( className.startsWith( prefix ) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return getEnhancer( loader ).enhance( className, classfileBuffer );
|
return getEnhancer( loader ).enhance( className, classfileBuffer );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue