< prev index next >

test/langtools/tools/javac/processing/T6439826.java

Print this page
rev 60625 : 8237041: AssertionError in parsing
Summary: Avoid parser crash for deeply nested classes without closing braces, improve error recovery for classes without an opening brace.
Reviewed-by: TBD


  43 @SupportedAnnotationTypes("*")
  44 public class T6439826 extends AbstractProcessor {
  45     public static void main(String... args) throws IOException {
  46         String testSrc = System.getProperty("test.src", ".");
  47         String testClasses = System.getProperty("test.classes");
  48         JavacTool tool = JavacTool.create();
  49         MyDiagListener dl = new MyDiagListener();
  50         try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
  51             Iterable<? extends JavaFileObject> files =
  52                 fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6439826.class.getName()+".java")));
  53             Iterable<String> opts = Arrays.asList("-proc:only",
  54                                                   "-processor", "T6439826",
  55                                                   "-processorpath", testClasses);
  56             StringWriter out = new StringWriter();
  57             JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
  58             task.call();
  59             String s = out.toString();
  60             System.err.print(s);
  61             // Expect the following 2 diagnostics, and no output to log
  62             //   Foo.java:1: illegal character: \35
  63             //   Foo.java:1: reached end of file while parsing
  64             System.err.println(dl.count + " diagnostics; " + s.length() + " characters");
  65             if (dl.count != 2 || s.length() != 0)
  66                 throw new AssertionError("unexpected output from compiler");
  67         }
  68     }
  69 
  70     public boolean process(Set<? extends TypeElement> annotations,
  71                            RoundEnvironment roundEnv) {
  72         Set<? extends TypeElement> elems = typesIn(roundEnv.getRootElements());
  73         for (TypeElement e: elems) {
  74             if (e.getSimpleName().toString().equals(T6439826.class.getName()))
  75                 writeBadFile();
  76         }
  77         return false;
  78     }
  79 
  80     @Override
  81     public SourceVersion getSupportedSourceVersion() {
  82         return SourceVersion.latest();
  83     }
  84 
  85     private void writeBadFile() {


  43 @SupportedAnnotationTypes("*")
  44 public class T6439826 extends AbstractProcessor {
  45     public static void main(String... args) throws IOException {
  46         String testSrc = System.getProperty("test.src", ".");
  47         String testClasses = System.getProperty("test.classes");
  48         JavacTool tool = JavacTool.create();
  49         MyDiagListener dl = new MyDiagListener();
  50         try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
  51             Iterable<? extends JavaFileObject> files =
  52                 fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6439826.class.getName()+".java")));
  53             Iterable<String> opts = Arrays.asList("-proc:only",
  54                                                   "-processor", "T6439826",
  55                                                   "-processorpath", testClasses);
  56             StringWriter out = new StringWriter();
  57             JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
  58             task.call();
  59             String s = out.toString();
  60             System.err.print(s);
  61             // Expect the following 2 diagnostics, and no output to log
  62             //   Foo.java:1: illegal character: \35

  63             System.err.println(dl.count + " diagnostics; " + s.length() + " characters");
  64             if (dl.count != 1 || s.length() != 0)
  65                 throw new AssertionError("unexpected output from compiler");
  66         }
  67     }
  68 
  69     public boolean process(Set<? extends TypeElement> annotations,
  70                            RoundEnvironment roundEnv) {
  71         Set<? extends TypeElement> elems = typesIn(roundEnv.getRootElements());
  72         for (TypeElement e: elems) {
  73             if (e.getSimpleName().toString().equals(T6439826.class.getName()))
  74                 writeBadFile();
  75         }
  76         return false;
  77     }
  78 
  79     @Override
  80     public SourceVersion getSupportedSourceVersion() {
  81         return SourceVersion.latest();
  82     }
  83 
  84     private void writeBadFile() {
< prev index next >