Skip to content

Commit

Permalink
fix classLoader#getURLs() may throw NullPointerException. fix #2968
Browse files Browse the repository at this point in the history
  • Loading branch information
hengyunabc committed Dec 2, 2024
1 parent 3bc5053 commit b266e1c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
Constants.WIKI + Constants.WIKI_HOME + "classloader")
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 String hashCode;
private String classLoaderClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
import java.util.List;
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
*
*/
public class ClassLoaderUtils {

private static Logger logger = LoggerFactory.getLogger(ClassLoaderUtils.class);
public static Set<ClassLoader> getAllClassLoader(Instrumentation inst) {
Set<ClassLoader> classLoaderSet = new HashSet<ClassLoader>();

Expand Down Expand Up @@ -127,7 +130,11 @@ else if (!StringUtils.isEmpty(classLoaderToString) && StringUtils.isEmpty(classL
@SuppressWarnings({ "unchecked", "restriction" })
public static URL[] getUrls(ClassLoader classLoader) {
if (classLoader instanceof URLClassLoader) {
return ((URLClassLoader) classLoader).getURLs();
try {
return ((URLClassLoader) classLoader).getURLs();
} catch (Throwable e) {
logger.error("classLoader: {} getUrls error", classLoader, e);
}
}

// jdk9
Expand Down

0 comments on commit b266e1c

Please sign in to comment.