fix classLoader#getURLs() may throw NullPointerException. fix #2968

pull/2979/head
hengyunabc 2 months ago
parent 3bc5053c69
commit b266e1c967

@ -57,7 +57,7 @@ import java.util.TreeSet;
Constants.WIKI + Constants.WIKI_HOME + "classloader") Constants.WIKI + Constants.WIKI_HOME + "classloader")
public class ClassLoaderCommand extends AnnotatedCommand { public class ClassLoaderCommand extends AnnotatedCommand {
private Logger logger = LoggerFactory.getLogger(ClassLoaderCommand.class); private static Logger logger = LoggerFactory.getLogger(ClassLoaderCommand.class);
private boolean isTree = false; private boolean isTree = false;
private String hashCode; private String hashCode;
private String classLoaderClass; private String classLoaderClass;

@ -9,13 +9,16 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import com.alibaba.arthas.deps.org.slf4j.Logger;
import com.alibaba.arthas.deps.org.slf4j.LoggerFactory;
/** /**
* *
* @author hengyunabc 2019-02-05 * @author hengyunabc 2019-02-05
* *
*/ */
public class ClassLoaderUtils { public class ClassLoaderUtils {
private static Logger logger = LoggerFactory.getLogger(ClassLoaderUtils.class);
public static Set<ClassLoader> getAllClassLoader(Instrumentation inst) { public static Set<ClassLoader> getAllClassLoader(Instrumentation inst) {
Set<ClassLoader> classLoaderSet = new HashSet<ClassLoader>(); Set<ClassLoader> classLoaderSet = new HashSet<ClassLoader>();
@ -127,7 +130,11 @@ public class ClassLoaderUtils {
@SuppressWarnings({ "unchecked", "restriction" }) @SuppressWarnings({ "unchecked", "restriction" })
public static URL[] getUrls(ClassLoader classLoader) { public static URL[] getUrls(ClassLoader classLoader) {
if (classLoader instanceof URLClassLoader) { if (classLoader instanceof URLClassLoader) {
try {
return ((URLClassLoader) classLoader).getURLs(); return ((URLClassLoader) classLoader).getURLs();
} catch (Throwable e) {
logger.error("classLoader: {} getUrls error", classLoader, e);
}
} }
// jdk9 // jdk9

Loading…
Cancel
Save