author | prr |
Fri, 25 May 2018 12:12:24 -0700 | |
changeset 50347 | b2f046ae8eb6 |
parent 48513 | 5b834ec96236 |
permissions | -rw-r--r-- |
48513
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
1 |
/* |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
4 |
* |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
8 |
* |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
13 |
* accompanied this code). |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
14 |
* |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
18 |
* |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
21 |
* questions. |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
22 |
*/ |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
23 |
|
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
24 |
/* |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
25 |
* @test 8187805 |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
26 |
* @summary bogus RuntimeVisibleTypeAnnotations for unused local in a block |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
27 |
* @modules jdk.jdeps/com.sun.tools.classfile |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
28 |
* jdk.compiler/com.sun.tools.javac.util |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
29 |
* @run main BogusRTTAForUnusedVarTest |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
30 |
*/ |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
31 |
|
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
32 |
import com.sun.tools.classfile.*; |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
33 |
|
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
34 |
import java.io.File; |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
35 |
import java.lang.annotation.Target; |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
36 |
import java.lang.annotation.ElementType; |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
37 |
import java.lang.annotation.Retention; |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
38 |
import java.lang.annotation.RetentionPolicy; |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
39 |
|
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
40 |
import com.sun.tools.classfile.Attribute; |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
41 |
import com.sun.tools.classfile.RuntimeVisibleTypeAnnotations_attribute; |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
42 |
import com.sun.tools.classfile.TypeAnnotation; |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
43 |
import com.sun.tools.classfile.TypeAnnotation.Position; |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
44 |
import com.sun.tools.javac.util.Assert; |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
45 |
|
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
46 |
public class BogusRTTAForUnusedVarTest { |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
47 |
|
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
48 |
class Foo { |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
49 |
void something() { |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
50 |
{ |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
51 |
@MyAnno Object o = new Object(); |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
52 |
} |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
53 |
} |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
54 |
} |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
55 |
|
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
56 |
@Target(ElementType.TYPE_USE) |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
57 |
@Retention(RetentionPolicy.RUNTIME) |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
58 |
@interface MyAnno {} |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
59 |
|
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
60 |
public static void main(String args[]) throws Throwable { |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
61 |
new BogusRTTAForUnusedVarTest().run(); |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
62 |
} |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
63 |
|
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
64 |
void run() throws Throwable { |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
65 |
checkRTTA(); |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
66 |
} |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
67 |
|
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
68 |
void checkRTTA() throws Throwable { |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
69 |
File testClasses = new File(System.getProperty("test.classes")); |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
70 |
File file = new File(testClasses, |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
71 |
BogusRTTAForUnusedVarTest.class.getName() + "$Foo.class"); |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
72 |
ClassFile classFile = ClassFile.read(file); |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
73 |
for (Method m : classFile.methods) { |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
74 |
if (m.getName(classFile.constant_pool).equals("something")) { |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
75 |
for (Attribute a : m.attributes) { |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
76 |
if (a.getName(classFile.constant_pool).equals("Code")) { |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
77 |
Code_attribute code = (Code_attribute)a; |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
78 |
for (Attribute codeAttrs : code.attributes) { |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
79 |
if (codeAttrs.getName(classFile.constant_pool).equals("RuntimeVisibleTypeAnnotations")) { |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
80 |
throw new AssertionError("no RuntimeVisibleTypeAnnotations attribute should have been generated in this case"); |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
81 |
} |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
82 |
} |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
83 |
} |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
84 |
} |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
85 |
} |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
86 |
} |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
87 |
} |
5b834ec96236
8187805: bogus RuntimeVisibleTypeAnnotations for unused local in a block
vromero
parents:
diff
changeset
|
88 |
} |