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

JSR 199: encoding option doesn't affect standard file manager

XMLWordPrintable

    • b47
    • 6
    • b55
    • generic
    • generic
    • Verified

      The attached test case fails. The test relies on an encoding
      which can't be saved in bugster notes, the code is in a comment,
      so here is the code without the comment:

      import java.io.File;
      import javax.tools.*;

      public class TestEncoding {
          static boolean error = false;
          public static void main(String[] args) {
              JavaCompilerTool compiler = ToolProvider.defaultJavaCompiler();
      compiler.setFileManager(compiler.getStandardFileManager());

              DiagnosticListener dl = new DiagnosticListener() {
                      public void report(DiagnosticMessage message) {
      if (message.getKind() == DiagnosticMessage.Kind.ERROR)
      error = true;
                          System.out.println(message.getSource()
      +":"+message.getStartPosition()+":"
      +message.getStartPosition()+":"+message.getPosition());
                          System.out.println(message.toString());
                          System.out.format("Found problem: %s%n", message.getKey());
                          System.out.flush();
                      }
              };
      String srcdir = System.getProperty("test.src");
      String sourceName = new File(srcdir, "TestEncoding.java").getPath();
      compiler.setOption("-source", 5);
      compiler.setOption("-encoding", "utf-8");
              compiler.run(null, dl, null, sourceName);
      if (error)
      throw new AssertionError("Error reported");
      error = false;
      compiler.setOption("-source", 5);
      compiler.setOption("-encoding", "ascii");
              compiler.run(null, dl, null, sourceName);
      if (!error)
      throw new AssertionError("No error reported");
      error = false;
      compiler.setOption("-source", 5);
      compiler.setOption("-encoding", "utf-8");
              compiler.run(null, dl, null, sourceName);
      if (error)
      throw new AssertionError("Error reported");
          }
      }

            ahe Peter Ahe
            ahe Peter Ahe
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: