Skip to content

Commit

Permalink
Remove reflective workaround for accessing `ClassLoader.getPlatformCl…
Browse files Browse the repository at this point in the history
…assLoader`

PiperOrigin-RevId: 425660155
  • Loading branch information
cushon authored and copybara-github committed Feb 1, 2022
1 parent 73520e9 commit 9b73ea4
Showing 1 changed file with 1 addition and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public Iterable<JavaFileObject> list(
protected ClassLoader getClassLoader(URL[] urls) {
return new URLClassLoader(
urls,
new ClassLoader(getPlatformClassLoader()) {
new ClassLoader(ClassLoader.getPlatformClassLoader()) {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
if (name.startsWith("com.google.errorprone.")
Expand All @@ -407,16 +407,5 @@ protected Class<?> findClass(String name) throws ClassNotFoundException {
}
}

public static ClassLoader getPlatformClassLoader() {
try {
// In JDK 9+, all platform classes are visible to the platform class loader:
// https://docs.oracle.com/javase/9/docs/api/java/lang/ClassLoader.html#getPlatformClassLoader--
return (ClassLoader) ClassLoader.class.getMethod("getPlatformClassLoader").invoke(null);
} catch (ReflectiveOperationException e) {
// In earlier releases, set 'null' as the parent to delegate to the boot class loader.
return null;
}
}

private BlazeJavacMain() {}
}

0 comments on commit 9b73ea4

Please sign in to comment.