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