diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/loading/ClassInjector.java b/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/loading/ClassInjector.java index c51ad13508a..a37b27514a1 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/loading/ClassInjector.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/loading/ClassInjector.java @@ -1818,22 +1818,15 @@ public Map> injectRaw(Map types) { : classLoader) { for (Map.Entry entry : types.entrySet()) { try { - // first try to load the class from the given class loader result.put(entry.getKey(), Class.forName(entry.getKey(), false, classLoader)); } catch (ClassNotFoundException ignored) { try { - // if the class does not exist, try to define it result.put(entry.getKey(), dispatcher.defineClass(classLoader, entry.getKey(), entry.getValue(), protectionDomain)); - } catch (Exception defFailure) { - // when the bootstrap loader is in use (i.e. the classloader is null), synchronizing on the BOOTSTRAP_LOADER_LOCK - // is sufficient to prevent this instance of ClassInjector from concurrently trying to define a class. - // however, in an environment where many ClassInjectors exist (either because shaded into multiple projects or - // it is present in multiple classloaders) + } catch (Exception exception) { // The bootstrap loader lock might be replicated throughout multiple class loaders. try { result.put(entry.getKey(), Class.forName(entry.getKey(), false, classLoader)); } catch (ClassNotFoundException ignored2) { - //throw the failure from actually trying to define the class - throw defFailure; + throw exception; } } }