Skip to content

Commit 7b2d5fc

Browse files
committed
8257856: Make ClassFileVersionsTest.java robust to JDK version updates
Reviewed-by: mbaesken Backport-of: 79aa7b15dbc54de891838ae2d4ca63838028c157
1 parent 6a28ccb commit 7b2d5fc

File tree

1 file changed

+51
-26
lines changed

1 file changed

+51
-26
lines changed

test/jdk/java/lang/module/ClassFileVersionsTest.java

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -43,40 +43,65 @@
4343
import static org.testng.Assert.*;
4444

4545
public class ClassFileVersionsTest {
46+
private static final int FEATURE;
47+
static {
48+
FEATURE = Runtime.version().feature();
49+
assert FEATURE >= 10;
50+
}
4651

4752
// major, minor, modifiers for requires java.base
4853
@DataProvider(name = "supported")
4954
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-
58-
{ 55, 0, Set.of()}, // JDK 11
59-
};
55+
/*
56+
* There are four test cases for JDK 9 and then one test case
57+
* for each subsequent JDK version from JDK 10 to the current
58+
* feature release for a total of (4 + (FEATURE - 9) ) =>
59+
* (feature - 5) rows.
60+
*/
61+
Object[][] result = new Object[(FEATURE - 5)][];
62+
63+
// Class file version of JDK 9 is 53.0
64+
result[0] = new Object[]{ 53, 0, Set.of()};
65+
result[1] = new Object[]{ 53, 0, Set.of(STATIC) };
66+
result[2] = new Object[]{ 53, 0, Set.of(TRANSITIVE) };
67+
result[3] = new Object[]{ 53, 0, Set.of(STATIC, TRANSITIVE) };
68+
69+
// Major class file version of JDK N is 44 + n. Create rows
70+
// for JDK 10 through FEATURE.
71+
for (int i = 4; i < (FEATURE - 5) ; i++) {
72+
result[i] = new Object[]{i + 50, 0, Set.of()};
73+
}
74+
75+
return result;
6076
}
6177

6278
// major, minor, modifiers for requires java.base
6379
@DataProvider(name = "unsupported")
6480
public Object[][] unsupported() {
65-
return new Object[][]{
66-
{ 50, 0, Set.of()}, // JDK 6
67-
{ 51, 0, Set.of()}, // JDK 7
68-
{ 52, 0, Set.of()}, // JDK 8
69-
70-
{ 54, 0, Set.of(STATIC) }, // JDK 10
71-
{ 54, 0, Set.of(TRANSITIVE) },
72-
{ 54, 0, Set.of(STATIC, TRANSITIVE) },
73-
74-
{ 55, 0, Set.of(STATIC) }, // JDK 11
75-
{ 55, 0, Set.of(TRANSITIVE) },
76-
{ 55, 0, Set.of(STATIC, TRANSITIVE) },
77-
78-
{ 56, 0, Set.of()}, // JDK 12
79-
};
81+
/*
82+
* There are three test cases for releases prior to JDK 9,
83+
* three test cases for each JDK version from JDK 10 to the
84+
* current feature release, plus one addition test case for
85+
* the next release for a total of (3 + (FEATURE - 9) * 3 + 1)
86+
* rows.
87+
*/
88+
int unsupportedCount = 3 + (FEATURE - 9)*3 + 1;
89+
Object[][] result = new Object[unsupportedCount][];
90+
91+
result[0] = new Object[]{50, 0, Set.of()}; // JDK 6
92+
result[1] = new Object[]{51, 0, Set.of()}; // JDK 7
93+
result[2] = new Object[]{52, 0, Set.of()}; // JDK 8
94+
95+
for (int i = 10; i <= FEATURE ; i++) {
96+
int base = 3 + (i-10)*3;
97+
// Major class file version of JDK N is 44+n
98+
result[base] = new Object[]{i + 44, 0, Set.of(STATIC)};
99+
result[base + 1] = new Object[]{i + 44, 0, Set.of(TRANSITIVE)};
100+
result[base + 2] = new Object[]{i + 44, 0, Set.of(STATIC, TRANSITIVE)};
101+
}
102+
103+
result[unsupportedCount - 1] = new Object[]{FEATURE+1+44, 0, Set.of()};
104+
return result;
80105
}
81106

82107
@Test(dataProvider = "supported")

0 commit comments

Comments
 (0)