test/tools/javac/T6181889/EmptyFinallyTest.java

changeset 0
959103a6100f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/T6181889/EmptyFinallyTest.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,67 @@
     1.4 +
     1.5 +import java.io.PrintWriter;
     1.6 +import java.io.StringWriter;
     1.7 +import java.nio.file.Paths;
     1.8 +
     1.9 +/*
    1.10 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    1.11 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    1.12 + *
    1.13 + * This code is free software; you can redistribute it and/or modify it
    1.14 + * under the terms of the GNU General Public License version 2 only, as
    1.15 + * published by the Free Software Foundation.
    1.16 + *
    1.17 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.18 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.19 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.20 + * version 2 for more details (a copy is included in the LICENSE file that
    1.21 + * accompanied this code).
    1.22 + *
    1.23 + * You should have received a copy of the GNU General Public License version
    1.24 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.25 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.26 + *
    1.27 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.28 + * or visit www.oracle.com if you need additional information or have any
    1.29 + * questions.
    1.30 + */
    1.31 +
    1.32 +/*
    1.33 + * @test
    1.34 + * @bug 6181889
    1.35 + * @summary Empty try/finally results in bytecodes being generated
    1.36 + */
    1.37 +
    1.38 +public class EmptyFinallyTest {
    1.39 +    private static final String assertionErrorMsg =
    1.40 +            "No \"Exception table\" should be generated in this case";
    1.41 +
    1.42 +    public static void main(String[] args) {
    1.43 +        new EmptyFinallyTest().run();
    1.44 +    }
    1.45 +
    1.46 +    void run() {
    1.47 +        check("-c", Paths.get(System.getProperty("test.classes"),
    1.48 +                "EmptyFinally.class").toString());
    1.49 +    }
    1.50 +
    1.51 +    void check(String... params) {
    1.52 +        StringWriter s;
    1.53 +        String out;
    1.54 +        try (PrintWriter pw = new PrintWriter(s = new StringWriter())) {
    1.55 +            com.sun.tools.javap.Main.run(params, pw);
    1.56 +            out = s.toString();
    1.57 +        }
    1.58 +        if (out.contains("Exception table")) {
    1.59 +            throw new AssertionError(assertionErrorMsg);
    1.60 +        }
    1.61 +    }
    1.62 +}
    1.63 +
    1.64 +class EmptyFinally {
    1.65 +    void m() {
    1.66 +        try {
    1.67 +            System.out.println("EMPTY TRY!");
    1.68 +        } finally {}
    1.69 +    }
    1.70 +}

mercurial