changeset 3780:7d2f8aa366e2

8155765: javax.tools.ToolProvider::getSystemToolClassLoader returns app class loader even if no tool is available Reviewed-by: mchung
author jjg
date Tue, 22 Nov 2016 16:29:24 -0800
parents faef6f72cf63
children 318dd5fce0ee
files src/java.compiler/share/classes/javax/tools/ToolProvider.java test/tools/javac/6410653/T6410653.java test/tools/javac/api/ToolProvider/ToolProviderTest.java test/tools/javac/options/release/ReleaseOptionClashes.java
diffstat 4 files changed, 21 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.compiler/share/classes/javax/tools/ToolProvider.java	Tue Nov 22 07:04:43 2016 -0800
+++ b/src/java.compiler/share/classes/javax/tools/ToolProvider.java	Tue Nov 22 16:29:24 2016 -0800
@@ -57,7 +57,7 @@
      * {@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 @@
      * {@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 @@
     }
 
     /**
-     * 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;
--- a/test/tools/javac/6410653/T6410653.java	Tue Nov 22 07:04:43 2016 -0800
+++ b/test/tools/javac/6410653/T6410653.java	Tue Nov 22 16:29:24 2016 -0800
@@ -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 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);
--- a/test/tools/javac/api/ToolProvider/ToolProviderTest.java	Tue Nov 22 07:04:43 2016 -0800
+++ b/test/tools/javac/api/ToolProvider/ToolProviderTest.java	Tue Nov 22 16:29:24 2016 -0800
@@ -55,6 +55,8 @@
 
         Objects.requireNonNull(ToolProvider.getSystemDocumentationTool());
         Objects.requireNonNull(ToolProvider.getSystemJavaCompiler());
-        Objects.requireNonNull(ToolProvider.getSystemToolClassLoader());
+        if (ToolProvider.getSystemToolClassLoader() != null) {
+            throw new AssertionError("unexpected value for getSystemToolClassLoader");
+        }
     }
 }
--- a/test/tools/javac/options/release/ReleaseOptionClashes.java	Tue Nov 22 07:04:43 2016 -0800
+++ b/test/tools/javac/options/release/ReleaseOptionClashes.java	Tue Nov 22 16:29:24 2016 -0800
@@ -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 @@
         compiler.run(null, null, System.out, options.toArray(new String[0]));
     }
 
-    ClassLoader cl = ToolProvider.getSystemToolClassLoader();
     Tool compiler = ToolProvider.getSystemJavaCompiler();
+    ClassLoader cl = compiler.getClass().getClassLoader();
 }