langtools/test/tools/javac/AnonymousSubclassTest.java
changeset 36778 e04318f39f92
parent 36526 3b41f1c69604
equal deleted inserted replaced
36777:28d33fb9097f 36778:e04318f39f92
     1 /*
     1 /*
     2  * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    25  * @test
    25  * @test
    26  * @bug 8023945
    26  * @bug 8023945
    27  * @summary javac wrongly allows a subclass of an anonymous class
    27  * @summary javac wrongly allows a subclass of an anonymous class
    28  * @library /tools/lib
    28  * @library /tools/lib
    29  * @modules jdk.compiler/com.sun.tools.javac.api
    29  * @modules jdk.compiler/com.sun.tools.javac.api
    30  *          jdk.compiler/com.sun.tools.javac.file
       
    31  *          jdk.compiler/com.sun.tools.javac.main
    30  *          jdk.compiler/com.sun.tools.javac.main
    32  *          jdk.jdeps/com.sun.tools.javap
    31  * @build toolbox.ToolBox toolbox.JavacTask
    33  * @build ToolBox
       
    34  * @run main AnonymousSubclassTest
    32  * @run main AnonymousSubclassTest
    35  */
    33  */
       
    34 
       
    35 import toolbox.JavacTask;
       
    36 import toolbox.Task;
       
    37 import toolbox.ToolBox;
    36 
    38 
    37 public class AnonymousSubclassTest {
    39 public class AnonymousSubclassTest {
    38     public static void main(String... args) throws Exception {
    40     public static void main(String... args) throws Exception {
    39         new AnonymousSubclassTest().run();
    41         new AnonymousSubclassTest().run();
    40     }
    42     }
    66         "    public T(Foo f) { super(f); }" +
    68         "    public T(Foo f) { super(f); }" +
    67         "  }"+
    69         "  }"+
    68         "}";
    70         "}";
    69 
    71 
    70     void compOk(String code) throws Exception {
    72     void compOk(String code) throws Exception {
    71         tb.new JavacTask()
    73         new JavacTask(tb)
    72                 .sources(code)
    74                 .sources(code)
    73                 .run();
    75                 .run();
    74     }
    76     }
    75 
    77 
    76     void compFail(String code) throws Exception {
    78     void compFail(String code) throws Exception {
    77         String errs = tb.new JavacTask()
    79         String errs = new JavacTask(tb)
    78                 .sources(code)
    80                 .sources(code)
    79                 .classpath(".")
    81                 .classpath(".")
    80                 .options("-XDrawDiagnostics")
    82                 .options("-XDrawDiagnostics")
    81                 .run(ToolBox.Expect.FAIL)
    83                 .run(Task.Expect.FAIL)
    82                 .writeAll()
    84                 .writeAll()
    83                 .getOutput(ToolBox.OutputKind.DIRECT);
    85                 .getOutput(Task.OutputKind.DIRECT);
    84 
    86 
    85         if (!errs.contains("cant.inherit.from.anon")) {
    87         if (!errs.contains("cant.inherit.from.anon")) {
    86             throw new Exception("test failed");
    88             throw new Exception("test failed");
    87         }
    89         }
    88     }
    90     }