4873
|
1 |
/*
|
5520
|
2 |
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
|
4873
|
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 |
*
|
5520
|
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.
|
4873
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* @test
|
|
26 |
* @bug 6918625
|
|
27 |
* @summary javap dumps type information of array class literals
|
|
28 |
*/
|
|
29 |
|
|
30 |
import java.io.*;
|
|
31 |
|
|
32 |
public class ArrayClassLiterals2 {
|
|
33 |
public static void main(String[] args) throws Exception {
|
|
34 |
new ArrayClassLiterals2().run();
|
|
35 |
}
|
|
36 |
|
|
37 |
public void run() throws IOException {
|
|
38 |
File classFile = new File(System.getProperty("test.classes"), "ArrayClassLiterals2$Test.class");
|
|
39 |
|
|
40 |
verify(classFile,
|
|
41 |
"RuntimeInvisibleTypeAnnotations:",
|
|
42 |
"CLASS_LITERAL_GENERIC_OR_ARRAY"
|
|
43 |
);
|
|
44 |
|
|
45 |
if (errors > 0)
|
|
46 |
throw new Error(errors + " found.");
|
|
47 |
}
|
|
48 |
|
|
49 |
String javap(File f) {
|
|
50 |
StringWriter sw = new StringWriter();
|
|
51 |
PrintWriter out = new PrintWriter(sw);
|
|
52 |
int rc = com.sun.tools.javap.Main.run(new String[] { "-v", f.getPath() }, out);
|
|
53 |
if (rc != 0)
|
|
54 |
throw new Error("javap failed. rc=" + rc);
|
|
55 |
out.close();
|
|
56 |
return sw.toString();
|
|
57 |
}
|
|
58 |
|
|
59 |
void verify(File classFile, String... expects) {
|
|
60 |
String output = javap(classFile);
|
|
61 |
for (String expect: expects) {
|
|
62 |
if (output.indexOf(expect)< 0)
|
|
63 |
error(expect + " not found");
|
|
64 |
}
|
|
65 |
}
|
|
66 |
|
|
67 |
void error(String msg) {
|
|
68 |
System.err.println(msg);
|
|
69 |
errors++;
|
|
70 |
}
|
|
71 |
|
|
72 |
int errors;
|
|
73 |
|
|
74 |
|
|
75 |
/*********************** Test class *************************/
|
|
76 |
static class Test {
|
|
77 |
@interface A { }
|
|
78 |
void test() {
|
|
79 |
Object a = @A String @A [] @A [].class;
|
|
80 |
}
|
|
81 |
}
|
|
82 |
}
|