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