Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/module/ClassFileVersionsTest.java
41149 views
1
/*
2
* Copyright (c) 2017, 2020, 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
* @modules java.base/jdk.internal.module
27
* @run testng ClassFileVersionsTest
28
* @summary Test parsing of module-info.class with different class file versions
29
*/
30
31
import java.lang.module.InvalidModuleDescriptorException;
32
import java.lang.module.ModuleDescriptor;
33
import java.lang.module.ModuleDescriptor.Requires.Modifier;
34
import java.nio.ByteBuffer;
35
import java.util.Set;
36
37
import static java.lang.module.ModuleDescriptor.Requires.Modifier.*;
38
39
import jdk.internal.module.ModuleInfoWriter;
40
41
import org.testng.annotations.DataProvider;
42
import org.testng.annotations.Test;
43
import static org.testng.Assert.*;
44
45
public class ClassFileVersionsTest {
46
47
// major, minor, modifiers for requires java.base
48
@DataProvider(name = "supported")
49
public Object[][] supported() {
50
return new Object[][]{
51
{ 53, 0, Set.of() }, // JDK 9
52
{ 53, 0, Set.of(STATIC) },
53
{ 53, 0, Set.of(TRANSITIVE) },
54
{ 53, 0, Set.of(STATIC, TRANSITIVE) },
55
56
{ 54, 0, Set.of() }, // JDK 10
57
{ 55, 0, Set.of() }, // JDK 11
58
{ 56, 0, Set.of() }, // JDK 12
59
{ 57, 0, Set.of() }, // JDK 13
60
{ 58, 0, Set.of() }, // JDK 14
61
{ 59, 0, Set.of() }, // JDK 15
62
{ 60, 0, Set.of() }, // JDK 16
63
{ 61, 0, Set.of() }, // JDK 17
64
};
65
}
66
67
// major, minor, modifiers for requires java.base
68
@DataProvider(name = "unsupported")
69
public Object[][] unsupported() {
70
return new Object[][]{
71
{ 50, 0, Set.of()}, // JDK 6
72
{ 51, 0, Set.of()}, // JDK 7
73
{ 52, 0, Set.of()}, // JDK 8
74
75
{ 54, 0, Set.of(STATIC) }, // JDK 10
76
{ 54, 0, Set.of(TRANSITIVE) },
77
{ 54, 0, Set.of(STATIC, TRANSITIVE) },
78
79
{ 55, 0, Set.of(STATIC) }, // JDK 11
80
{ 55, 0, Set.of(TRANSITIVE) },
81
{ 55, 0, Set.of(STATIC, TRANSITIVE) },
82
83
{ 56, 0, Set.of(STATIC) }, // JDK 12
84
{ 56, 0, Set.of(TRANSITIVE) },
85
{ 56, 0, Set.of(STATIC, TRANSITIVE) },
86
87
{ 57, 0, Set.of(STATIC) }, // JDK 13
88
{ 57, 0, Set.of(TRANSITIVE) },
89
{ 57, 0, Set.of(STATIC, TRANSITIVE) },
90
91
{ 58, 0, Set.of(STATIC) }, // JDK 14
92
{ 58, 0, Set.of(TRANSITIVE) },
93
{ 58, 0, Set.of(STATIC, TRANSITIVE) },
94
95
{ 59, 0, Set.of(STATIC) }, // JDK 15
96
{ 59, 0, Set.of(TRANSITIVE) },
97
{ 59, 0, Set.of(STATIC, TRANSITIVE) },
98
99
{ 60, 0, Set.of(STATIC) }, // JDK 16
100
{ 60, 0, Set.of(TRANSITIVE) },
101
{ 60, 0, Set.of(STATIC, TRANSITIVE) },
102
103
{ 61, 0, Set.of(STATIC) }, // JDK 17
104
{ 61, 0, Set.of(TRANSITIVE) },
105
{ 61, 0, Set.of(STATIC, TRANSITIVE) },
106
107
{ 62, 0, Set.of()}, // JDK 18
108
};
109
}
110
111
@Test(dataProvider = "supported")
112
public void testSupported(int major, int minor, Set<Modifier> ms) {
113
ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo")
114
.requires(ms, "java.base")
115
.build();
116
ByteBuffer bb = ModuleInfoWriter.toByteBuffer(descriptor);
117
classFileVersion(bb, major, minor);
118
descriptor = ModuleDescriptor.read(bb);
119
assertEquals(descriptor.name(), "foo");
120
}
121
122
@Test(dataProvider = "unsupported",
123
expectedExceptions = InvalidModuleDescriptorException.class)
124
public void testUnsupported(int major, int minor, Set<Modifier> ms) {
125
ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo")
126
.requires(ms, "java.base")
127
.build();
128
ByteBuffer bb = ModuleInfoWriter.toByteBuffer(descriptor);
129
classFileVersion(bb, major, minor);
130
131
// throws InvalidModuleDescriptorException
132
ModuleDescriptor.read(bb);
133
}
134
135
private void classFileVersion(ByteBuffer bb, int major, int minor) {
136
bb.putShort(4, (short) minor);
137
bb.putShort(6, (short) major);
138
}
139
}
140
141