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