Skip to content

Commit

Permalink
Merge pull request #10670 from pshipton/fixnpe
Browse files Browse the repository at this point in the history
Fix possible NPE in J9VMInternals.getClassInfoStrings()
  • Loading branch information
keithc-ca authored Sep 24, 2020
2 parents 7591bf3 + 7bf8cd0 commit a8d5927
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions jcl/src/java.base/share/classes/java/lang/J9VMInternals.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@
import java.util.Properties;
import java.util.WeakHashMap;
import java.security.AccessControlContext;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
import java.net.URL;
/*[IF Sidecar19-SE]*/
import jdk.internal.ref.CleanerShutdown;
import jdk.internal.ref.CleanerImpl;
Expand Down Expand Up @@ -492,25 +491,39 @@ static final class ClassInitializationLock {


private static String[] getClassInfoStrings(final Class<?> clazz, String classPath){
String classLoader;
String classLoaderStr = "<Bootstrap Loader>"; //$NON-NLS-1$
String cpResult = "<Unknown>"; //$NON-NLS-1$

if (classPath != null) {
classLoader = "<Bootstrap Loader>";
} else {
classLoader = clazz.getClassLoader().toString();
classPath = (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
String path = null;
try {
path = clazz.getProtectionDomain().getCodeSource().getLocation().toString();
} catch (Exception e) {
path = "<Unknown>";
if (classPath == null) {
ClassLoader classLoader = clazz.getClassLoader();
if (classLoader != null) {
classLoaderStr = classLoader.toString();
classPath = AccessController.doPrivileged(new PrivilegedAction<String>() {
@Override
public String run() {
String path = null;
try {
ProtectionDomain pd = clazz.getProtectionDomain();
if (pd != null) {
CodeSource cs = pd.getCodeSource();
if (cs != null) {
URL loc = cs.getLocation();
if (loc != null) {
path = loc.toString();
}
}
}
} catch (Exception e) {
}
return path;
}
return path;
}
});
});
}
}
if (classPath != null) {
cpResult = classPath;
}
String [] strings = {classPath, classLoader};
String [] strings = {cpResult, classLoaderStr};
return strings;
}

Expand Down

0 comments on commit a8d5927

Please sign in to comment.