author | martin |
Tue, 15 Sep 2015 21:56:04 -0700 | |
changeset 32649 | 2ee9017c7597 |
parent 20481 | 2735b307d256 |
permissions | -rw-r--r-- |
19588
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
1 |
/* |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
4 |
* |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
8 |
* |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
13 |
* accompanied this code). |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
14 |
* |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
18 |
* |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
21 |
* questions. |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
22 |
*/ |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
23 |
|
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
24 |
/* |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
25 |
* @test |
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
26 |
* @bug 8022343 8007072 |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
27 |
* @summary Test Class.getAnnotatedSuperclass() returns null/non-null |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
28 |
* AnnotatedType as specified |
19588
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
29 |
*/ |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
30 |
|
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
31 |
import java.lang.reflect.AnnotatedType; |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
32 |
import java.util.Arrays; |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
33 |
|
19588
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
34 |
public class GetAnnotatedSuperclass { |
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
35 |
private static final Class<?>[] nullTestData = { |
19588
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
36 |
Object.class, |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
37 |
If.class, |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
38 |
Object[].class, |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
39 |
void.class, |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
40 |
int.class, |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
41 |
}; |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
42 |
|
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
43 |
private static final Class<?>[] nonNullTestData = { |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
44 |
Class.class, |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
45 |
GetAnnotatedSuperclass.class, |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
46 |
(new If() {}).getClass(), |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
47 |
(new Clz() {}).getClass(), |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
48 |
(new Object() {}).getClass(), |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
49 |
}; |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
50 |
|
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
51 |
private static int failed = 0; |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
52 |
private static int tests = 0; |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
53 |
|
19588
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
54 |
public static void main(String[] args) throws Exception { |
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
55 |
testReturnsNull(); |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
56 |
testReturnsEmptyAT(); |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
57 |
|
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
58 |
if (failed != 0) |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
59 |
throw new RuntimeException("Test failed, check log for details"); |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
60 |
if (tests != 10) |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
61 |
throw new RuntimeException("Not all cases ran, failing"); |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
62 |
} |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
63 |
|
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
64 |
private static void testReturnsNull() { |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
65 |
for (Class<?> toTest : nullTestData) { |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
66 |
tests++; |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
67 |
|
19588
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
68 |
Object res = toTest.getAnnotatedSuperclass(); |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
69 |
|
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
70 |
if (res != null) { |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
71 |
failed++; |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
72 |
System.out.println(toTest + ".getAnnotatedSuperclass() returns: " |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
73 |
+ res + ", should be null"); |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
74 |
} |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
75 |
} |
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
76 |
} |
19588
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
77 |
|
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
78 |
private static void testReturnsEmptyAT() { |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
79 |
for (Class<?> toTest : nonNullTestData) { |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
80 |
tests++; |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
81 |
|
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
82 |
AnnotatedType res = toTest.getAnnotatedSuperclass(); |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
83 |
|
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
84 |
if (res == null) { |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
85 |
failed++; |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
86 |
System.out.println(toTest + ".getAnnotatedSuperclass() returns 'null' should be non-null"); |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
87 |
} else if (res.getAnnotations().length != 0) { |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
88 |
failed++; |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
89 |
System.out.println(toTest + ".getAnnotatedSuperclass() returns: " |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
90 |
+ Arrays.asList(res.getAnnotations()) + ", should be an empty AnnotatedType"); |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
91 |
} |
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
92 |
} |
19588
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
93 |
} |
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
94 |
|
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
95 |
interface If {} |
20481
2735b307d256
8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
19588
diff
changeset
|
96 |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
20481
diff
changeset
|
97 |
abstract static class Clz {} |
19588
5f7c7cdd74e9
8022343: j.l.Class.getAnnotatedSuperclass() doesn't return null in some cases
jfranck
parents:
diff
changeset
|
98 |
} |