Mon, 17 Oct 2011 12:57:36 +0100
7093325: Redundant entry in bytecode exception table
Summary: Inlining of finalizers does not update gaps list accordingly
Reviewed-by: jjg
jjg@944 | 1 | /* |
jjg@944 | 2 | * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
jjg@944 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@944 | 4 | * |
jjg@944 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@944 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@944 | 7 | * published by the Free Software Foundation. |
jjg@944 | 8 | * |
jjg@944 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@944 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@944 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@944 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@944 | 13 | * accompanied this code). |
jjg@944 | 14 | * |
jjg@944 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@944 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@944 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@944 | 18 | * |
jjg@944 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jjg@944 | 20 | * or visit www.oracle.com if you need additional information or have any |
jjg@944 | 21 | * questions. |
jjg@944 | 22 | */ |
jjg@944 | 23 | |
jjg@944 | 24 | /** |
jjg@944 | 25 | * @test |
darcy@1044 | 26 | * @bug 6597678 6449184 |
jjg@944 | 27 | * @summary Ensure Messages propogated between rounds |
jjg@944 | 28 | * @library ../lib |
jjg@944 | 29 | * @build JavacTestingAbstractProcessor T6597678 |
jjg@944 | 30 | * @run main T6597678 |
jjg@944 | 31 | */ |
jjg@944 | 32 | |
jjg@944 | 33 | import java.io.*; |
jjg@944 | 34 | import java.util.*; |
jjg@944 | 35 | import javax.annotation.processing.RoundEnvironment; |
jjg@944 | 36 | import javax.annotation.processing.SupportedOptions; |
jjg@944 | 37 | import javax.lang.model.element.TypeElement; |
jjg@944 | 38 | import javax.tools.Diagnostic; |
jjg@944 | 39 | |
jjg@944 | 40 | |
jjg@944 | 41 | import com.sun.tools.javac.processing.JavacProcessingEnvironment; |
jjg@944 | 42 | import com.sun.tools.javac.util.Context; |
jjg@944 | 43 | import com.sun.tools.javac.util.JavacMessages; |
jjg@944 | 44 | |
darcy@1044 | 45 | @SupportedOptions("WriterString") |
jjg@944 | 46 | public class T6597678 extends JavacTestingAbstractProcessor { |
jjg@944 | 47 | public static void main(String... args) throws Exception { |
jjg@944 | 48 | new T6597678().run(); |
jjg@944 | 49 | } |
jjg@944 | 50 | |
jjg@944 | 51 | void run() throws Exception { |
jjg@944 | 52 | String myName = T6597678.class.getSimpleName(); |
jjg@944 | 53 | File testSrc = new File(System.getProperty("test.src")); |
jjg@944 | 54 | File file = new File(testSrc, myName + ".java"); |
jjg@944 | 55 | |
darcy@1044 | 56 | StringWriter sw = new StringWriter(); |
darcy@1044 | 57 | PrintWriter pw = new PrintWriter(sw); |
darcy@1044 | 58 | |
darcy@1044 | 59 | compile(sw, pw, |
jjg@944 | 60 | "-proc:only", |
jjg@944 | 61 | "-processor", myName, |
darcy@1044 | 62 | "-AWriterString=" + pw.toString(), |
jjg@944 | 63 | file.getPath()); |
jjg@944 | 64 | } |
jjg@944 | 65 | |
darcy@1044 | 66 | void compile(StringWriter sw, PrintWriter pw, String... args) throws Exception { |
jjg@944 | 67 | int rc = com.sun.tools.javac.Main.compile(args, pw); |
jjg@944 | 68 | pw.close(); |
jjg@944 | 69 | String out = sw.toString(); |
jjg@944 | 70 | if (!out.isEmpty()) |
jjg@944 | 71 | System.err.println(out); |
jjg@944 | 72 | if (rc != 0) |
jjg@944 | 73 | throw new Exception("compilation failed unexpectedly: rc=" + rc); |
jjg@944 | 74 | } |
jjg@944 | 75 | |
jjg@944 | 76 | //--------------- |
jjg@944 | 77 | |
jjg@944 | 78 | @Override |
jjg@944 | 79 | public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
jjg@944 | 80 | Context context = ((JavacProcessingEnvironment) processingEnv).getContext(); |
darcy@1044 | 81 | PrintWriter out = ((JavacProcessingEnvironment) processingEnv).getWriter(); |
jjg@944 | 82 | Locale locale = context.get(Locale.class); |
jjg@944 | 83 | JavacMessages messages = context.get(JavacMessages.messagesKey); |
jjg@944 | 84 | |
jjg@944 | 85 | round++; |
jjg@944 | 86 | if (round == 1) { |
jjg@944 | 87 | initialLocale = locale; |
jjg@944 | 88 | initialMessages = messages; |
darcy@1044 | 89 | initialWriter = out; |
darcy@1044 | 90 | |
darcy@1044 | 91 | checkEqual("writerString", out.toString().intern(), options.get("WriterString").intern()); |
jjg@944 | 92 | } else { |
jjg@944 | 93 | checkEqual("locale", locale, initialLocale); |
jjg@944 | 94 | checkEqual("messages", messages, initialMessages); |
darcy@1044 | 95 | checkEqual("writer", out, initialWriter); |
jjg@944 | 96 | } |
jjg@944 | 97 | |
jjg@944 | 98 | return true; |
jjg@944 | 99 | } |
jjg@944 | 100 | |
jjg@944 | 101 | <T> void checkEqual(String label, T actual, T expected) { |
jjg@944 | 102 | if (actual != expected) |
jjg@944 | 103 | messager.printMessage(Diagnostic.Kind.ERROR, |
jjg@944 | 104 | "Unexpected value for " + label |
jjg@944 | 105 | + "; expected: " + expected |
jjg@944 | 106 | + "; found: " + actual); |
jjg@944 | 107 | } |
jjg@944 | 108 | |
jjg@944 | 109 | int round = 0; |
jjg@944 | 110 | Locale initialLocale; |
jjg@944 | 111 | JavacMessages initialMessages; |
darcy@1044 | 112 | PrintWriter initialWriter; |
jjg@944 | 113 | } |