Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/annotation/ExceptionalToString/ExceptionalToStringTest.java
41154 views
1
/*
2
* Copyright (c) 2016, 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
*/
23
24
/*
25
* @test
26
* @bug 5040830
27
* @summary Verify information annotation strings with exception proxies
28
* @compile -sourcepath version1 version1/Fleeting.java version1/Utopia.java version1/DangerousAnnotation.java
29
* @compile AnnotationHost.java
30
* @build ExceptionalToStringTest
31
* @run main ExceptionalToStringTest
32
* @clean Utopia DangerousAnnotation
33
* @compile -sourcepath version2 -implicit:none version2/Utopia.java
34
* @compile -sourcepath version2 -implicit:none version2/DangerousAnnotation.java
35
* @clean Fleeting
36
* @run main ExceptionalToStringTest
37
*/
38
39
/**
40
* There are three potential exception conditions which can occur
41
* reading annotations:
42
*
43
* EnumConstantNotPresentException - "Thrown when an application tries
44
* to access an enum constant by name and the enum type contains no
45
* constant with the specified name."
46
*
47
* AnnotationTypeMismatchException - "Thrown to indicate that a
48
* program has attempted to access an element of an annotation whose
49
* type has changed after the annotation was compiled (or serialized)"
50
*
51
* TypeNotPresentException - "Thrown when an application tries to
52
* access a type using a string representing the type's name, but no
53
* definition for the type with the specified name can be found."
54
*
55
* The test reads an annotation, DangerousAnnotation, which can
56
* display all three pathologies. The pathologies are <em>not</em>
57
* present when the version1 sources are used but are present with the
58
* version2 sources. The version2 sources remove an enum constant
59
* (EnumConstantNotPresentException), change the return type of an
60
* annotation method (AnnotationTypeMismatchException), and remove a
61
* type whose Class literal is referenced (TypeNotPresentException).
62
*/
63
public class ExceptionalToStringTest {
64
public static void main(String... args) {
65
String annotationAsString = AnnotationHost.class.getAnnotation(DangerousAnnotation.class).toString();
66
67
// Verify no occurrence of "ExceptionProxy" in the string.
68
if (annotationAsString.indexOf("ExceptionProxy") != -1) {
69
throw new RuntimeException();
70
}
71
}
72
}
73
74