mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 11:04:34 +02:00
8155765: javax.tools.ToolProvider::getSystemToolClassLoader returns app class loader even if no tool is available
Reviewed-by: mchung
This commit is contained in:
parent
fe1b93aeab
commit
2d7092c7ac
4 changed files with 21 additions and 15 deletions
|
@ -57,7 +57,7 @@ public class ToolProvider {
|
|||
* {@code null} if no compiler is provided
|
||||
* @implNote This implementation returns the compiler provided
|
||||
* by the {@code jdk.compiler} module if that module is available,
|
||||
* and null otherwise.
|
||||
* and {@code null} otherwise.
|
||||
*/
|
||||
public static JavaCompiler getSystemJavaCompiler() {
|
||||
return getSystemTool(JavaCompiler.class,
|
||||
|
@ -78,7 +78,7 @@ public class ToolProvider {
|
|||
* {@code null} if no documentation tool is provided
|
||||
* @implNote This implementation returns the tool provided
|
||||
* by the {@code jdk.javadoc} module if that module is available,
|
||||
* and null otherwise.
|
||||
* and {@code null} otherwise.
|
||||
*/
|
||||
public static DocumentationTool getSystemDocumentationTool() {
|
||||
return getSystemTool(DocumentationTool.class,
|
||||
|
@ -86,16 +86,19 @@ public class ToolProvider {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the class loader for tools provided with this platform.
|
||||
* This does not include user-installed tools. Use the
|
||||
* {@linkplain java.util.ServiceLoader service provider mechanism}
|
||||
* for locating user installed tools.
|
||||
*
|
||||
* @return the class loader for tools provided with this platform
|
||||
* or {@code null} if no tools are provided
|
||||
* Returns a class loader that may be used to load system tools,
|
||||
* or {@code null} if no such special loader is provided.
|
||||
* @implSpec This implementation always returns {@code null}.
|
||||
* @deprecated This method is subject to removal in a future version of
|
||||
* Java SE.
|
||||
* Use the {@link java.util.spi.ToolProvider system tool provider} or
|
||||
* {@link java.util.ServiceLoader service loader} mechanisms to
|
||||
* locate system tools as well as user-installed tools.
|
||||
* @return a class loader, or {@code null}
|
||||
*/
|
||||
@Deprecated
|
||||
public static ClassLoader getSystemToolClassLoader() {
|
||||
return ClassLoader.getSystemClassLoader();
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final boolean useLegacy;
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
*/
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Module;
|
||||
import java.io.File;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import javax.tools.*;
|
||||
|
@ -39,9 +40,9 @@ public class T6410653 {
|
|||
public static void main(String... args) throws Exception {
|
||||
File testSrc = new File(System.getProperty("test.src"));
|
||||
String source = new File(testSrc, "T6410653.java").getPath();
|
||||
ClassLoader cl = ToolProvider.getSystemToolClassLoader();
|
||||
Tool compiler = ToolProvider.getSystemJavaCompiler();
|
||||
Class<?> log = Class.forName("com.sun.tools.javac.util.Log", true, cl);
|
||||
Module compilerModule = compiler.getClass().getModule();
|
||||
Class<?> log = Class.forName(compilerModule, "com.sun.tools.javac.util.Log");
|
||||
Field useRawMessages = log.getDeclaredField("useRawMessages");
|
||||
useRawMessages.setAccessible(true);
|
||||
useRawMessages.setBoolean(null, true);
|
||||
|
|
|
@ -55,6 +55,8 @@ public class ToolProviderTest {
|
|||
|
||||
Objects.requireNonNull(ToolProvider.getSystemDocumentationTool());
|
||||
Objects.requireNonNull(ToolProvider.getSystemJavaCompiler());
|
||||
Objects.requireNonNull(ToolProvider.getSystemToolClassLoader());
|
||||
if (ToolProvider.getSystemToolClassLoader() != null) {
|
||||
throw new AssertionError("unexpected value for getSystemToolClassLoader");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -82,6 +82,6 @@ public class ReleaseOptionClashes {
|
|||
compiler.run(null, null, System.out, options.toArray(new String[0]));
|
||||
}
|
||||
|
||||
ClassLoader cl = ToolProvider.getSystemToolClassLoader();
|
||||
Tool compiler = ToolProvider.getSystemJavaCompiler();
|
||||
ClassLoader cl = compiler.getClass().getClassLoader();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue