8344471: Remove SecurityManager related code from java.compiler module

Reviewed-by: rriggs, jlahoda, jjg
This commit is contained in:
Jaikiran Pai 2024-11-21 00:49:25 +00:00
parent b9bf447209
commit a599c30171

View File

@ -25,8 +25,6 @@
package javax.tools; package javax.tools;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Objects; import java.util.Objects;
import java.util.ServiceConfigurationError; import java.util.ServiceConfigurationError;
import java.util.ServiceLoader; import java.util.ServiceLoader;
@ -118,29 +116,13 @@ public class ToolProvider {
try { try {
ServiceLoader<T> sl = ServiceLoader.load(clazz, ClassLoader.getSystemClassLoader()); ServiceLoader<T> sl = ServiceLoader.load(clazz, ClassLoader.getSystemClassLoader());
for (T tool : sl) { for (T tool : sl) {
if (matches(tool, moduleName)) if (Objects.equals(tool.getClass().getModule().getName(), moduleName)) {
return tool; return tool;
}
} }
} catch (ServiceConfigurationError e) { } catch (ServiceConfigurationError e) {
throw new Error(e); throw new Error(e);
} }
return null; return null;
} }
/**
* Determine if this is the desired tool instance.
* @param <T> the interface of the tool
* @param tool the instance of the tool
* @param moduleName the name of the module containing the desired implementation
* @return true if and only if the tool matches the specified criteria
*/
@SuppressWarnings("removal")
private static <T> boolean matches(T tool, String moduleName) {
PrivilegedAction<Boolean> pa = () -> {
Module toolModule = tool.getClass().getModule();
String toolModuleName = toolModule.getName();
return Objects.equals(toolModuleName, moduleName);
};
return AccessController.doPrivileged(pa);
}
} }