Don't inject helpers into the same classloader twice

This commit is contained in:
Andrew Kent 2017-12-15 10:08:45 -08:00
parent 887a864118
commit 069f481884
1 changed files with 11 additions and 5 deletions

View File

@ -18,6 +18,7 @@ import net.bytebuddy.utility.JavaModule;
public class HelperInjector implements Transformer { public class HelperInjector implements Transformer {
private final Set<String> helperClassNames; private final Set<String> helperClassNames;
private Map<TypeDescription, byte[]> helperMap = null; private Map<TypeDescription, byte[]> helperMap = null;
private final Set<ClassLoader> injectedClassLoaders = new HashSet<ClassLoader>();
/** /**
* Construct HelperInjector. * Construct HelperInjector.
@ -49,11 +50,16 @@ public class HelperInjector implements Transformer {
ClassLoader classLoader, ClassLoader classLoader,
JavaModule module) { JavaModule module) {
if (helperClassNames.size() > 0 && classLoader != null) { if (helperClassNames.size() > 0 && classLoader != null) {
try { synchronized (this) {
new ClassInjector.UsingReflection(classLoader).inject(getHelperMap()); if (!injectedClassLoaders.contains(classLoader)) {
} catch (ClassNotFoundException cnfe) { try {
log.error("Failed to inject helper classes into " + classLoader, cnfe); new ClassInjector.UsingReflection(classLoader).inject(getHelperMap());
throw new RuntimeException(cnfe); } catch (ClassNotFoundException cnfe) {
log.error("Failed to inject helper classes into " + classLoader, cnfe);
throw new RuntimeException(cnfe);
}
injectedClassLoaders.add(classLoader);
}
} }
} }
return builder; return builder;