8241353: NPE in ToolProvider.getSystemJavaCompiler

Reviewed-by: vromero
This commit is contained in:
Jonathan Gibbons 2020-12-16 22:21:54 +00:00
parent 87644a2bb7
commit 6b4b676550

View File

@ -27,7 +27,7 @@ package javax.tools;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Iterator;
import java.util.Objects;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
@ -118,8 +118,7 @@ public class ToolProvider {
try {
ServiceLoader<T> sl = ServiceLoader.load(clazz, ClassLoader.getSystemClassLoader());
for (Iterator<T> iter = sl.iterator(); iter.hasNext(); ) {
T tool = iter.next();
for (T tool : sl) {
if (matches(tool, moduleName))
return tool;
}
@ -140,7 +139,7 @@ public class ToolProvider {
PrivilegedAction<Boolean> pa = () -> {
Module toolModule = tool.getClass().getModule();
String toolModuleName = toolModule.getName();
return toolModuleName.equals(moduleName);
return Objects.equals(toolModuleName, moduleName);
};
return AccessController.doPrivileged(pa);
}