2 Replies Latest reply: Oct 4, 2010 8:03 AM by 802700 RSS

    javax.tools.StandardJavaFileManager 32bit/ 64bit issue

    802700
      Hi,

      I have created the java code given below which compiles another java file passed into it and executes it. I have tested the above code on java version 1.6.0_03(32 bit) and the latest java 6 64bit version.

      When compiled using the 32bit version of the compiler the code executes without any problems with the desired results when invoked with the java command in the command line. However when I do the same thing on a 64bit compiler using the same code it throws an runtime exception in the form of a Null Pointer in the line shown in bold face font. I reverted back to 32bit and it works fine.

      My question is what is the reason for this abnormal behaviour of the StandardJavaFileManager in the 32bit and 64bit compilers? Any insight in this regard is mcuh appretiated.

      Rgds,
      Wicky


      import java.io.IOException;
      import java.util.Arrays;
      import java.io.InputStream;

      import javax.tools.DiagnosticCollector;
      import javax.tools.JavaCompiler;
      import javax.tools.JavaFileObject;
      import javax.tools.StandardJavaFileManager;
      import javax.tools.ToolProvider;

      public class DiagnosticCollectorCompile {

      public static void main(String args[]) throws IOException {
      JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
      DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
      StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
      Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromStrings(Arrays.asList("MyClass.java"));
      JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, null,null, compilationUnits);
      boolean success = task.call();
      fileManager.close();
      System.out.println("Success: " + success);
      Runtime rt1 = Runtime.getRuntime();
      String java= "D:/Program Files (x86)/Java/jdk1.6.0_03/bin/java";
      Process p1 =rt1.exec(new String[]{ java, "MyClass" });
      InputStream inp = p1.getInputStream();
      int charIn1;
      while( (charIn1 = inp.read()) != -1 )
      {
      System.out.print( (char)charIn1 );
      }
      }}