Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/annotation/Missing/MissingArrayElement/MissingAnnotationArrayElementTest.java
41154 views
1
/*
2
* Copyright (c) 2018, Google Inc. 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
*/
23
24
import static java.lang.annotation.RetentionPolicy.RUNTIME;
25
26
import java.lang.annotation.Retention;
27
import java.lang.reflect.Constructor;
28
import java.lang.reflect.Method;
29
30
/*
31
* @test
32
* @bug 7183985
33
* @summary getAnnotation() should throw NoClassDefFoundError when an annotation class is not
34
* present at runtime
35
* @compile MissingAnnotationArrayElementTest.java MissingAnnotation.java
36
* @clean MissingAnnotation
37
* @run main MissingAnnotationArrayElementTest
38
*/
39
public class MissingAnnotationArrayElementTest {
40
41
@Retention(RUNTIME)
42
@interface AnnotationAnnotation {
43
MissingAnnotation[] value();
44
}
45
46
@AnnotationAnnotation({@MissingAnnotation, @MissingAnnotation})
47
static class Test {
48
void f(@AnnotationAnnotation({@MissingAnnotation, @MissingAnnotation}) int x) {}
49
50
Test(@AnnotationAnnotation({@MissingAnnotation, @MissingAnnotation}) int x) {}
51
}
52
53
public static void main(String[] args) throws Exception {
54
// MissingAnnotation will be absent from the runtime classpath, causing a
55
// NoClassDefFoundError when AnnotationAnnotation is read (since the type of its value array
56
// references cannot be completed).
57
assertThrowsNoClassDefFoundError(
58
() -> Test.class.getAnnotation(AnnotationAnnotation.class));
59
Method method = Test.class.getDeclaredMethod("f", int.class);
60
assertThrowsNoClassDefFoundError(method::getParameterAnnotations);
61
Constructor constructor = Test.class.getDeclaredConstructor(int.class);
62
assertThrowsNoClassDefFoundError(constructor::getParameterAnnotations);
63
}
64
65
interface ThrowingRunnable {
66
void run() throws Exception;
67
}
68
69
static void assertThrowsNoClassDefFoundError(ThrowingRunnable throwingRunnable)
70
throws Exception {
71
try {
72
throwingRunnable.run();
73
throw new AssertionError("expected exception");
74
} catch (NoClassDefFoundError expected) {
75
if (!expected.getMessage().contains("MissingAnnotation")) {
76
throw expected;
77
}
78
}
79
}
80
}
81
82