Skip to content
This repository has been archived by the owner on May 3, 2018. It is now read-only.

Commit

Permalink
[MODULES-172] Prevent access error when logging provider load failure
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Jul 18, 2013
1 parent d9c5804 commit 957bc94
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/main/java/__redirected/__RedirectedUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.UndeclaredThrowableException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -36,6 +38,7 @@
import org.jboss.modules.ModuleIdentifier;
import org.jboss.modules.ModuleLoadException;
import org.jboss.modules.ModuleLoader;
import org.jboss.modules.log.ModuleLogger;

/**
* Common utilities for redirected factories
Expand All @@ -45,6 +48,19 @@
*/
public final class __RedirectedUtils {

static ModuleLogger getModuleLogger() {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
return AccessController.doPrivileged(new PrivilegedAction<ModuleLogger>() {
public ModuleLogger run() {
return Module.getModuleLogger();
}
});
} else {
return Module.getModuleLogger();
}
}

static RuntimeException rethrowCause(Throwable t) throws Error {
try {
throw t.getCause();
Expand Down Expand Up @@ -75,7 +91,7 @@ static <T> Class<? extends T> loadProvider(ModuleIdentifier id, Class<T> intf, M
try {
module = moduleLoader.loadModule(id);
} catch (ModuleLoadException e) {
Module.getModuleLogger().providerUnloadable(id.toString(), null);
getModuleLogger().providerUnloadable(id.toString(), null);
return null;
}

Expand All @@ -91,15 +107,15 @@ static <T> Class<? extends T> loadProvider(Class<T> intf, ClassLoader classLoade
List<String> names = findProviderClassNames(intf, classLoader, name);

if (names.isEmpty()) {
Module.getModuleLogger().providerUnloadable("Not found", classLoader);
getModuleLogger().providerUnloadable("Not found", classLoader);
return null;
}

String clazzName = names.get(0);
try {
return classLoader.loadClass(clazzName).asSubclass(intf);
} catch (Exception ignore) {
Module.getModuleLogger().providerUnloadable(clazzName, classLoader);
getModuleLogger().providerUnloadable(clazzName, classLoader);
return null;
}
}
Expand All @@ -112,7 +128,7 @@ static <T> List<Class<? extends T>> loadProviders(Class<T> intf, ClassLoader cla
List<String> names = findProviderClassNames(intf, classLoader, name);

if (names.size() < 1) {
Module.getModuleLogger().providerUnloadable("Not found", classLoader);
getModuleLogger().providerUnloadable("Not found", classLoader);
return Collections.emptyList();
}

Expand All @@ -122,7 +138,7 @@ static <T> List<Class<? extends T>> loadProviders(Class<T> intf, ClassLoader cla
try {
classes.add(classLoader.loadClass(className).asSubclass(intf));
} catch (Exception ignore) {
Module.getModuleLogger().providerUnloadable(className, classLoader);
getModuleLogger().providerUnloadable(className, classLoader);
}
}

Expand Down

0 comments on commit 957bc94

Please sign in to comment.