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
1 /*
2 * Copyright (c) 2011, 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 */
24 /**
25 * @test
26 * @bug 6597678 6449184
27 * @summary Ensure Messages propogated between rounds
28 * @library ../lib
29 * @build JavacTestingAbstractProcessor T6597678
30 * @run main T6597678
31 */
33 import java.io.*;
34 import java.util.*;
35 import javax.annotation.processing.RoundEnvironment;
36 import javax.annotation.processing.SupportedOptions;
37 import javax.lang.model.element.TypeElement;
38 import javax.tools.Diagnostic;
41 import com.sun.tools.javac.processing.JavacProcessingEnvironment;
42 import com.sun.tools.javac.util.Context;
43 import com.sun.tools.javac.util.JavacMessages;
45 @SupportedOptions("WriterString")
46 public class T6597678 extends JavacTestingAbstractProcessor {
47 public static void main(String... args) throws Exception {
48 new T6597678().run();
49 }
51 void run() throws Exception {
52 String myName = T6597678.class.getSimpleName();
53 File testSrc = new File(System.getProperty("test.src"));
54 File file = new File(testSrc, myName + ".java");
56 StringWriter sw = new StringWriter();
57 PrintWriter pw = new PrintWriter(sw);
59 compile(sw, pw,
60 "-proc:only",
61 "-processor", myName,
62 "-AWriterString=" + pw.toString(),
63 file.getPath());
64 }
66 void compile(StringWriter sw, PrintWriter pw, String... args) throws Exception {
67 int rc = com.sun.tools.javac.Main.compile(args, pw);
68 pw.close();
69 String out = sw.toString();
70 if (!out.isEmpty())
71 System.err.println(out);
72 if (rc != 0)
73 throw new Exception("compilation failed unexpectedly: rc=" + rc);
74 }
76 //---------------
78 @Override
79 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
80 Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
81 PrintWriter out = ((JavacProcessingEnvironment) processingEnv).getWriter();
82 Locale locale = context.get(Locale.class);
83 JavacMessages messages = context.get(JavacMessages.messagesKey);
85 round++;
86 if (round == 1) {
87 initialLocale = locale;
88 initialMessages = messages;
89 initialWriter = out;
91 checkEqual("writerString", out.toString().intern(), options.get("WriterString").intern());
92 } else {
93 checkEqual("locale", locale, initialLocale);
94 checkEqual("messages", messages, initialMessages);
95 checkEqual("writer", out, initialWriter);
96 }
98 return true;
99 }
101 <T> void checkEqual(String label, T actual, T expected) {
102 if (actual != expected)
103 messager.printMessage(Diagnostic.Kind.ERROR,
104 "Unexpected value for " + label
105 + "; expected: " + expected
106 + "; found: " + actual);
107 }
109 int round = 0;
110 Locale initialLocale;
111 JavacMessages initialMessages;
112 PrintWriter initialWriter;
113 }