Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7200408

ToolProvider.getSystemJavaCompiler() returns null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: P3 P3
    • None
    • 7
    • tools
    • x86
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.7.0_05"
      Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
      Java HotSpot(TM) Client VM (build 23.1-b03, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7 32 bits
      Microsoft Windows [version 6.1.7601]


      A DESCRIPTION OF THE PROBLEM :
      I use the jre and I have included tools.jar in my classpath

        ToolProvider.getSystemJavaCompiler() returns null;

      This code works and gives me a compiler :
      compiler = (JavaCompiler) Class.forName("com.sun.tools.javac.api.JavacTool").newInstance();

      Note : It works with java 6 versions .

      REGRESSION. Last worked in version 6u31

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use a jre, include tools.jar from the jdk in your classpath
      execute ToolProvider.getSystemJavaCompiler()
      it returns null

      execute (JavaCompiler) Class.forName("com.sun.tools.javac.api.JavacTool").newInstance();
      it returns a compiler

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
        ToolProvider.getSystemJavaCompiler() should return a compiler
      ACTUAL -
      it returns null

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      import javax.tools.JavaCompiler;
      import javax.tools.ToolProvider;

      public class Test {

      public static void main(String[] args) {
      try {
      JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
      if (compiler == null) {
      System.out.println("ToolProvider.getSystemJavaCompiler() returned null");
      compiler = (JavaCompiler) Class.forName("com.sun.tools.javac.api.JavacTool").newInstance();
      System.out.println("But here is a compiler : " + compiler);
      }
      } catch (Exception e) {
      e.printStackTrace();
      }
      }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      JavaCompiler compiler = (JavaCompiler) Class.forName("com.sun.tools.javac.api.JavacTool").newInstance();

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: