|
| 1 | +/* |
| 2 | + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 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 |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +/* |
| 25 | + * @test |
| 26 | + * @bug 8301580 |
| 27 | + * @summary Verify error recovery w.r.t. Attr |
| 28 | + * @library /tools/lib |
| 29 | + * @modules jdk.compiler/com.sun.tools.javac.api |
| 30 | + * jdk.compiler/com.sun.tools.javac.main |
| 31 | + * jdk.jdeps/com.sun.tools.classfile |
| 32 | + * @build toolbox.ToolBox toolbox.JavacTask |
| 33 | + * @run main AttrRecovery |
| 34 | + */ |
| 35 | + |
| 36 | +import java.nio.file.Path; |
| 37 | +import java.util.List; |
| 38 | +import java.util.Objects; |
| 39 | + |
| 40 | +import toolbox.JavacTask; |
| 41 | +import toolbox.Task.Expect; |
| 42 | +import toolbox.Task.OutputKind; |
| 43 | +import toolbox.TestRunner; |
| 44 | +import toolbox.ToolBox; |
| 45 | + |
| 46 | +public class AttrRecovery extends TestRunner { |
| 47 | + |
| 48 | + ToolBox tb; |
| 49 | + |
| 50 | + public AttrRecovery() { |
| 51 | + super(System.err); |
| 52 | + tb = new ToolBox(); |
| 53 | + } |
| 54 | + |
| 55 | + public static void main(String[] args) throws Exception { |
| 56 | + AttrRecovery t = new AttrRecovery(); |
| 57 | + t.runTests(); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void testFlowExits() throws Exception { |
| 62 | + String code = """ |
| 63 | + class C { |
| 64 | + void build |
| 65 | + { |
| 66 | + return ; |
| 67 | + } |
| 68 | + } |
| 69 | + """; |
| 70 | + Path curPath = Path.of("."); |
| 71 | + List<String> actual = new JavacTask(tb) |
| 72 | + .options("-XDrawDiagnostics", "-XDdev", "-XDshould-stop.at=FLOW") |
| 73 | + .sources(code) |
| 74 | + .outdir(curPath) |
| 75 | + .run(Expect.FAIL) |
| 76 | + .getOutputLines(OutputKind.DIRECT); |
| 77 | + |
| 78 | + List<String> expected = List.of( |
| 79 | + "C.java:3:5: compiler.err.expected: '('", |
| 80 | + "C.java:4:9: compiler.err.ret.outside.meth", |
| 81 | + "2 errors" |
| 82 | + ); |
| 83 | + |
| 84 | + if (!Objects.equals(actual, expected)) { |
| 85 | + error("Expected: " + expected + ", but got: " + actual); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | +} |
0 commit comments