ExceptionTest.java revision 3294:9adfb22ff08f
1/*
2 * Copyright (c) 2015, 2016, 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 8049238
27 * @summary Checks Signature attribute for methods which throw exceptions.
28 * @library /tools/lib /tools/javac/lib ../lib
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
32 *          jdk.jdeps/com.sun.tools.classfile
33 *          jdk.jdeps/com.sun.tools.javap
34 * @build TestBase TestResult InMemoryFileManager ToolBox
35 * @build ExceptionTest Driver ExpectedSignature ExpectedSignatureContainer
36 * @run main Driver ExceptionTest
37 */
38
39import java.io.IOError;
40import java.io.IOException;
41
42@ExpectedSignature(descriptor = "ExceptionTest",
43        signature = "<Exc:Ljava/lang/RuntimeException;:Ljava/lang/Runnable;>Ljava/lang/Object;")
44public class ExceptionTest<Exc extends RuntimeException & Runnable> {
45
46    @ExpectedSignature(descriptor = "<init>()", signature = "<E:Ljava/lang/Exception;>()V^TE;")
47    <E extends Exception> ExceptionTest() throws E {
48    }
49
50    @ExpectedSignature(descriptor = "<init>(int)",
51            signature = "<E:Ljava/lang/Exception;>(I)V^Ljava/io/IOException;^TE;^Ljava/io/IOError;")
52    <E extends Exception> ExceptionTest(int a) throws IOException, E, IOError {
53    }
54
55    @ExpectedSignature(descriptor = "<init>(long)", signature = "(J)V^TExc;")
56    ExceptionTest(long a) throws Exc {
57    }
58
59    @ExpectedSignature(descriptor = "<init>(byte)", signature = "(B)V^Ljava/io/IOError;^TExc;^Ljava/io/IOException;")
60    ExceptionTest(byte a) throws IOError, Exc, IOException {
61    }
62
63    @ExpectedSignature(descriptor = "<init>(java.lang.RuntimeException)", signature = "(TExc;)V")
64    ExceptionTest(Exc a) throws IOException {
65    }
66
67    // no Signature attribute
68    ExceptionTest(String a) throws IOError {
69    }
70
71    void noSignatureAttributeMethod() throws IOException {
72    }
73
74    @ExpectedSignature(descriptor = "genericMethod(int)", signature = "(I)V^TExc;")
75    void genericMethod(int a) throws Exc {
76    }
77
78    @ExpectedSignature(descriptor = "genericMethod(long)", signature = "(J)V^TExc;^Ljava/io/IOException;")
79    void genericMethod(long a) throws Exc, IOException {
80    }
81
82    @ExpectedSignature(descriptor = "genericMethod(java.lang.RuntimeException)", signature = "(TExc;)V")
83    void genericMethod(Exc a) throws IOError {
84    }
85
86    static void staticNoSignatureAttributeMethod() throws IOException {
87    }
88
89    @ExpectedSignature(descriptor = "staticGenericMethod(int)",
90            signature = "<E:Ljava/lang/Exception;:Ljava/lang/Runnable;>(I)V^TE;")
91    static <E extends Exception & Runnable> void staticGenericMethod(int a) throws E {
92    }
93
94    @ExpectedSignature(descriptor = "staticGenericMethod(long)",
95            signature = "<E:Ljava/lang/Exception;>(J)V^Ljava/io/IOError;^TE;^Ljava/io/IOException;")
96    static <E extends Exception> void staticGenericMethod(long a) throws IOError, E, IOException {
97    }
98
99    @ExpectedSignature(descriptor = "staticGenericMethod(java.lang.Exception)",
100            signature = "<E:Ljava/lang/Exception;>(TE;)V")
101    static <E extends Exception> void staticGenericMethod(E a) throws IOError {
102    }
103}
104