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

Minor doc bugs in JavaCompiler.java

XMLWordPrintable

    • b128
    • generic
    • generic
    • Not verified

      Three minor doc bugs in JavaCompiler.java code example :

      The doc says :
      <DiagnosticCollector_example_code >
          Used to collect diagnostics in a list, for example:

                 Iterable<? extends JavaFileObject> compilationUnits = ...;
                 JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
                 DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
                 StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
                 compiler.getTask(null, fileManager, diagnostics, null, null, compilationUnits).call();

                 for (Diagnostic diagnostic : diagnostics.getDiagnostics())
                     System.out.format("Error on line %d in %d%n",
                                       diagnostic.getLineNumber()
                                       diagnostic.getSource().toUri());

                 fileManager.close();

      </DiagnosticCollector_example_code >

      1)for (Diagnostic diagnostic : diagnostics.getDiagnostics()) should be
      *for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics.getDiagnostics()) *
      since
      a) toUri() method is directly calling on dignostic.getSource() method
                 ***diagnostic.getSource().toUri()) ***
      b) diagnostics is already of type JavaFileObject

      2)System.out.format has both '%d's, it should be one %d and other %s since first one points to number but second one pointes to a String.
      System.out.format("Error on line %d in **%s**%n",

      3) ',' is missing between diagnostic.getLineNumber and diagnostic.getSource

            jjg Jonathan Gibbons
            savadhansunw Seetharama Avadhanam (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: