Skip to content

Commit

Permalink
Added priviledge access for multiple parent class loader.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jul 19, 2016
1 parent 745752e commit 0df3b71
Showing 1 changed file with 28 additions and 2 deletions.
Expand Up @@ -2,6 +2,7 @@

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.utility.privilege.ClassLoaderAction;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -338,7 +339,20 @@ private Builder(List<? extends ClassLoader> classLoaders) {
* yet collected.
*/
public Builder append(Class<?>... type) {
return append(Arrays.asList(type));
return append(AccessController.getContext(), type);
}

/**
* Appends the class loaders of the given types. The bootstrap class loader is implicitly skipped as
* it is an implicit parent of any class loader.
*
* @param accessControlContext The access control context to use.
* @param type The types of which to collect the class loaders.
* @return A new builder instance with the additional class loaders of the provided types if they were not
* yet collected.
*/
public Builder append(AccessControlContext accessControlContext, Class<?>... type) {
return append(accessControlContext, Arrays.asList(type));
}

/**
Expand All @@ -349,9 +363,21 @@ public Builder append(Class<?>... type) {
* @return A new builder instance with the additional class loaders.
*/
public Builder append(Collection<? extends Class<?>> types) {
return append(AccessController.getContext(), types);
}

/**
* Appends the class loaders of the given types if those class loaders were not yet collected. The bootstrap class
* loader is implicitly skipped as it is an implicit parent of any class loader.
*
* @param accessControlContext The access control context to use.
* @param types The types of which to collect the class loaders.
* @return A new builder instance with the additional class loaders.
*/
public Builder append(AccessControlContext accessControlContext, Collection<? extends Class<?>> types) {
List<ClassLoader> classLoaders = new ArrayList<ClassLoader>(types.size());
for (Class<?> type : types) {
classLoaders.add(type.getClassLoader());
classLoaders.add(ClassLoaderAction.apply(type, accessControlContext));
}
return append(classLoaders);
}
Expand Down

0 comments on commit 0df3b71

Please sign in to comment.