Skip to content

Commit

Permalink
Refactored class loder use to check for null when the bootstrap class…
Browse files Browse the repository at this point in the history
… loder is returned.
  • Loading branch information
raphw committed Nov 15, 2015
1 parent 8a1a09c commit 1fdd613
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Expand Up @@ -1095,9 +1095,11 @@ protected enum Accessor {
Accessor() {
try {
TypeDescription nexusType = new TypeDescription.ForLoadedType(Nexus.class);
ClassLoader classLoader = Accessor.class.getClassLoader(); // null if Byte Buddy is added to the bootstrap class path.
Class<?> nexus = new ClassInjector.UsingReflection(ClassLoader.getSystemClassLoader())
.inject(Collections.singletonMap(nexusType, new StreamDrainer()
.drain(getClass().getClassLoader().getResourceAsStream(Nexus.class.getName().replace('.', '/') + ".class"))))
.inject(Collections.singletonMap(nexusType, new StreamDrainer().drain((classLoader == null
? ClassLoader.getSystemClassLoader()
: classLoader).getResourceAsStream(Nexus.class.getName().replace('.', '/') + ".class"))))
.get(nexusType);
registration = nexus.getDeclaredMethod("register", String.class, ClassLoader.class, int.class, Object.class);
getSystemClassLoader = new TypeDescription.ForLoadedType(ClassLoader.class).getDeclaredMethods()
Expand Down
Expand Up @@ -111,9 +111,10 @@ public Explicit(byte[] binaryRepresentation) {
* @return The binary data to this type which might be illegal.
*/
public static Resolution of(Class<?> type) {
InputStream inputStream = (type.getClassLoader() == null
ClassLoader classLoader = type.getClassLoader();
InputStream inputStream = (classLoader == null
? ClassLoader.getSystemClassLoader()
: type.getClassLoader()).getResourceAsStream(type.getName().replace('.', '/') + CLASS_FILE_EXTENSION);
: classLoader).getResourceAsStream(type.getName().replace('.', '/') + CLASS_FILE_EXTENSION);
if (inputStream == null) {
return Illegal.INSTANCE;
} else {
Expand Down
Expand Up @@ -176,7 +176,10 @@ public ClassReloadingStrategy reset(Class<?>... type) {
Map<Class<?>, ClassDefinition> classDefinitions = new ConcurrentHashMap<Class<?>, ClassDefinition>(type.length);
try {
for (Class<?> aType : type) {
InputStream inputStream = aType.getClassLoader().getResourceAsStream(aType.getName().replace('.', '/') + CLASS_FILE_EXTENSION);
ClassLoader classLoader = aType.getClassLoader();
InputStream inputStream = (classLoader == null
? ClassLoader.getSystemClassLoader()
: classLoader).getResourceAsStream(aType.getName().replace('.', '/') + CLASS_FILE_EXTENSION);
try {
classDefinitions.put(aType, new ClassDefinition(aType, new StreamDrainer().drain(inputStream)));
} finally {
Expand Down

0 comments on commit 1fdd613

Please sign in to comment.