JDK-7181951 : ToolProvider.getSystemJavaCompiler() is null if tools.jar put to jre/lib/ext dir
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_7
  • CPU: x86
  • Submitted: 2012-07-05
  • Updated: 2012-07-13
  • Resolved: 2012-07-13
Description
FULL PRODUCT VERSION :
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows 7x64 SP1
Windows XP SP3

A DESCRIPTION OF THE PROBLEM :
Adding tools.jar to "jre/lib/ext" folder does not work anymore. In JDK 6 it was possible to add tools.jar to "jre/lib/ext" folder and have system java compiler be returned by javax.tools.ToolProvider.getSystemJavaCompiler().
Now with JDK 7 it is no longer working. If I add jar to "jre/lib/ext" folder then ToolProvider.getSystemJavaCompiler() returns null. But if add tools.jar to the "jre/lib" folder then it works.

REGRESSION.  Last worked in version 6u31

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Install JRE 1.7.0_05
2. Compile test code provided.
3. Copy tools.jar to jre/lib/ext folder
4. Run code => and error will be thrown
5. Now move tools.jar from jre/lib/ext to jre/lib folder and re-run => it will work

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
javax.tools.ToolProvider.getSystemJavaCompiler() should return an instance of JavaCompiler class
ACTUAL -
javax.tools.ToolProvider.getSystemJavaCompiler() returns null

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.tools.JavaCompiler;

public class CompilerTest {
  public static void main(String[] args) {
    JavaCompiler systemCompiler =
        javax.tools.ToolProvider.getSystemJavaCompiler();
    if (systemCompiler == null) {
      throw new Error("systemCompiler == null!");
    }
  }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Copy tools.jar to "jre/lib" folder instead of "jre/lib/ext" folder

Comments
EVALUATION Closing as not a bug. That behavior was neither specified nor intended.
13-07-2012

EVALUATION I am able to reproduce this as described since JDK7 FCS and in JDK8, if tools.jar is placed in jre/lib/ext then the test case fails, javax.tools.ToolProvider.getSystemJavaCompiler() returns null. The same test using 6u33 does not fail.
12-07-2012