Don't inject helpers into the same classloader twice
@@ -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,12 +50,17 @@ public class HelperInjector implements Transformer {
ClassLoader classLoader,
JavaModule module) {
if (helperClassNames.size() > 0 && classLoader != null) {
+ 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;
}
