Skip to content

Commit 79de8f4

Browse files
liachDavid Simms
authored andcommitted
8357054: [lworld] tools/javac/valhalla/value-objects/ test still using com.sun.tools.classfile
1 parent 8c53ea5 commit 79de8f4

File tree

5 files changed

+84
-103
lines changed

5 files changed

+84
-103
lines changed

test/langtools/ProblemList.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ tools/javac/annotations/typeAnnotations/referenceinfos/NestedTypes.java
6262
tools/javac/warnings/suppress/TypeAnnotations.java 8057683 generic-all improve ordering of errors with type annotations
6363
tools/javac/modules/SourceInSymlinkTest.java 8180263 windows-all fails when run on a subst drive
6464

65-
tools/javac/valhalla/value-objects/LoadableDescriptorsAttrTest2.java 8357054 generic-all
66-
tools/javac/valhalla/value-objects/LoadableDescriptorsAttributeTest.java 8357054 generic-all
67-
tools/javac/valhalla/value-objects/NoUnnecessaryLoadableDescriptorsTest.java 8357054 generic-all
68-
tools/javac/valhalla/value-objects/ValueBasedFlagsTest.java 8357054 generic-all
69-
7065
###########################################################################
7166
#
7267
# javap

test/langtools/tools/javac/valhalla/value-objects/LoadableDescriptorsAttrTest2.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2024, 2025, 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
@@ -37,17 +37,15 @@
3737
* @run main LoadableDescriptorsAttrTest2
3838
*/
3939

40+
import java.lang.classfile.Attributes;
41+
import java.lang.classfile.ClassFile;
4042
import java.nio.file.Path;
4143
import java.nio.file.Paths;
4244

43-
import com.sun.tools.javac.code.Flags;
4445
import com.sun.tools.javac.util.Assert;
45-
import com.sun.tools.classfile.ClassFile;
4646

4747
import toolbox.TestRunner;
4848
import toolbox.ToolBox;
49-
import toolbox.JavacTask;
50-
import toolbox.Task;
5149

5250
public class LoadableDescriptorsAttrTest2 extends TestRunner {
5351
ToolBox tb = new ToolBox();
@@ -90,9 +88,9 @@ class Ident {
9088
.run()
9189
.writeAll();
9290
Path classFilePath = classes.resolve("Ident.class");
93-
ClassFile classFile = ClassFile.read(classFilePath.toFile());
94-
Assert.check(classFile.minor_version == 65535);
95-
Assert.check(classFile.attributes.get("LoadableDescriptors") != null);
91+
var classFile = ClassFile.of().parse(classFilePath);
92+
Assert.check(classFile.minorVersion() == 65535);
93+
Assert.check(classFile.findAttribute(Attributes.loadableDescriptors()).isPresent());
9694

9795
// now with the value class in the classpath
9896
new toolbox.JavacTask(tb)
@@ -103,9 +101,9 @@ class Ident {
103101
.writeAll();
104102

105103
classFilePath = classes.resolve("Ident.class");
106-
classFile = ClassFile.read(classFilePath.toFile());
107-
Assert.check(classFile.minor_version == 65535);
108-
Assert.check(classFile.attributes.get("LoadableDescriptors") != null);
104+
classFile = ClassFile.of().parse(classFilePath);
105+
Assert.check(classFile.minorVersion() == 65535);
106+
Assert.check(classFile.findAttribute(Attributes.loadableDescriptors()).isPresent());
109107
}
110108

111109
@Test
@@ -130,9 +128,9 @@ void m(Val val) {}
130128
.run()
131129
.writeAll();
132130
Path classFilePath = classes.resolve("Ident.class");
133-
ClassFile classFile = ClassFile.read(classFilePath.toFile());
134-
Assert.check(classFile.minor_version == 65535);
135-
Assert.check(classFile.attributes.get("LoadableDescriptors") != null);
131+
var classFile = ClassFile.of().parse(classFilePath);
132+
Assert.check(classFile.minorVersion() == 65535);
133+
Assert.check(classFile.findAttribute(Attributes.loadableDescriptors()).isPresent());
136134

137135
// now with the value class in the classpath
138136
new toolbox.JavacTask(tb)
@@ -143,9 +141,10 @@ void m(Val val) {}
143141
.writeAll();
144142

145143
classFilePath = classes.resolve("Ident.class");
146-
classFile = ClassFile.read(classFilePath.toFile());
147-
Assert.check(classFile.minor_version == 65535);
148-
Assert.check(classFile.attributes.get("LoadableDescriptors") != null);
144+
classFile = ClassFile.of().parse(classFilePath);
145+
Assert.check(classFile.minorVersion() == 65535);
146+
Assert.check(classFile.findAttribute(Attributes.loadableDescriptors()).isPresent());
147+
149148
}
150149

151150
@Test
@@ -172,9 +171,10 @@ Val m() {
172171
.run()
173172
.writeAll();
174173
Path classFilePath = classes.resolve("Ident.class");
175-
ClassFile classFile = ClassFile.read(classFilePath.toFile());
176-
Assert.check(classFile.minor_version == 65535);
177-
Assert.check(classFile.attributes.get("LoadableDescriptors") != null);
174+
var classFile = ClassFile.of().parse(classFilePath);
175+
Assert.check(classFile.minorVersion() == 65535);
176+
Assert.check(classFile.findAttribute(Attributes.loadableDescriptors()).isPresent());
177+
178178

179179
// now with the value class in the classpath
180180
new toolbox.JavacTask(tb)
@@ -185,8 +185,9 @@ Val m() {
185185
.writeAll();
186186

187187
classFilePath = classes.resolve("Ident.class");
188-
classFile = ClassFile.read(classFilePath.toFile());
189-
Assert.check(classFile.minor_version == 65535);
190-
Assert.check(classFile.attributes.get("LoadableDescriptors") != null);
188+
classFile = ClassFile.of().parse(classFilePath);
189+
Assert.check(classFile.minorVersion() == 65535);
190+
Assert.check(classFile.findAttribute(Attributes.loadableDescriptors()).isPresent());
191+
191192
}
192193
}

test/langtools/tools/javac/valhalla/value-objects/LoadableDescriptorsAttributeTest.java

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2025, 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
@@ -30,8 +30,12 @@
3030
* @run main LoadableDescriptorsAttributeTest
3131
*/
3232

33-
import com.sun.tools.classfile.*;
34-
import com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8_info;
33+
import java.lang.classfile.Attributes;
34+
import java.lang.classfile.ClassFile;
35+
import java.lang.classfile.ClassModel;
36+
import java.lang.classfile.constantpool.Utf8Entry;
37+
import java.util.Set;
38+
import java.util.stream.Collectors;
3539

3640
public class LoadableDescriptorsAttributeTest {
3741

@@ -73,38 +77,30 @@ void goo(V6[] v6) { // parameter uses value type but as array component - no pre
7377
// So we expect ONLY V2, V3, V7 to be in LoadableDescriptors list
7478

7579
public static void main(String[] args) throws Exception {
76-
ClassFile cls = ClassFile.read(LoadableDescriptorsAttributeTest.class.getResourceAsStream("LoadableDescriptorsAttributeTest$X.class"));
77-
78-
if (cls == null) {
79-
throw new AssertionError("Could not locate the class files");
80+
ClassModel cls;
81+
try (var in = LoadableDescriptorsAttributeTest.class.getResourceAsStream("LoadableDescriptorsAttributeTest$X.class")) {
82+
cls = ClassFile.of().parse(in.readAllBytes());
8083
}
8184

8285
/* Check emission of LoadableDescriptors attribute */
83-
LoadableDescriptors_attribute descriptors = (LoadableDescriptors_attribute) cls.attributes.get(Attribute.LoadableDescriptors);
84-
if (descriptors == null) {
85-
throw new AssertionError("Missing LoadableDescriptors attribute!");
86-
}
87-
if (descriptors.number_of_descriptors != 3) {
88-
throw new AssertionError("Incorrect number of loadable descriptors, found: " + descriptors.number_of_descriptors);
86+
var descriptors = cls.findAttribute(Attributes.loadableDescriptors()).orElseThrow();
87+
if (descriptors.loadableDescriptors().size() != 3) {
88+
throw new AssertionError("Expected 3 loadable descriptors, found: " + descriptors.loadableDescriptors());
8989
}
9090

91-
int mask = 7;
92-
for (int i = 0; i < descriptors.number_of_descriptors; i++) {
93-
CONSTANT_Utf8_info clsInfo = cls.constant_pool.getUTF8Info(
94-
descriptors.descriptors[i]);
95-
switch (clsInfo.value) {
96-
case "LLoadableDescriptorsAttributeTest$V2;":
97-
mask &= ~1; break;
98-
case "LLoadableDescriptorsAttributeTest$V3;":
99-
mask &= ~2; break;
100-
case "LLoadableDescriptorsAttributeTest$V7;" :
101-
mask &= ~4; break;
102-
default:
103-
throw new AssertionError("Unexpected LoadableDescriptors entry!");
104-
}
105-
}
106-
if (mask != 0) {
107-
throw new AssertionError("Some LoadableDescriptors entries are missing!");
91+
Set<String> expected = Set.of(
92+
"LLoadableDescriptorsAttributeTest$V2;",
93+
"LLoadableDescriptorsAttributeTest$V3;",
94+
"LLoadableDescriptorsAttributeTest$V7;"
95+
);
96+
97+
Set<String> found = descriptors.loadableDescriptors()
98+
.stream()
99+
.map(Utf8Entry::stringValue)
100+
.collect(Collectors.toSet());
101+
102+
if (!expected.equals(found)) {
103+
throw new AssertionError("LoadableDescriptors mismatch, found: " + found);
108104
}
109105
}
110106
}
Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2025, 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
@@ -30,8 +30,12 @@
3030
* @run main NoUnnecessaryLoadableDescriptorsTest
3131
*/
3232

33-
import com.sun.tools.classfile.*;
34-
import com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8_info;
33+
import java.lang.classfile.Attributes;
34+
import java.lang.classfile.ClassFile;
35+
import java.lang.classfile.ClassModel;
36+
import java.lang.classfile.attribute.LoadableDescriptorsAttribute;
37+
import java.lang.classfile.constantpool.Utf8Entry;
38+
import java.util.List;
3539

3640
public class NoUnnecessaryLoadableDescriptorsTest {
3741

@@ -50,80 +54,65 @@ static value class Inner2 {}
5054
}
5155

5256
public static void main(String[] args) throws Exception {
57+
ClassModel cls;
58+
LoadableDescriptorsAttribute loadableDescriptors;
5359

5460
// There should be no LoadableDescriptors attribute in NoUnnecessaryLoadableDescriptorsTest.class
55-
ClassFile cls = ClassFile.read(NoUnnecessaryLoadableDescriptorsTest.class.getResourceAsStream("NoUnnecessaryLoadableDescriptorsTest.class"));
56-
57-
if (cls == null) {
58-
throw new AssertionError("Could not locate the class files");
61+
try (var in = NoUnnecessaryLoadableDescriptorsTest.class.getResourceAsStream("NoUnnecessaryLoadableDescriptorsTest.class")) {
62+
cls = ClassFile.of().parse(in.readAllBytes());
5963
}
6064

6165
/* Check emission of LoadableDescriptors attribute */
62-
LoadableDescriptors_attribute LoadableDescriptors = (LoadableDescriptors_attribute) cls.attributes.get(Attribute.LoadableDescriptors);
63-
if (LoadableDescriptors != null) {
66+
if (cls.findAttribute(Attributes.loadableDescriptors()).isPresent()) {
6467
throw new AssertionError("Unexpected LoadableDescriptors attribute!");
6568
}
6669

6770
// There should be no LoadableDescriptors attribute in NoUnnecessaryLoadableDescriptorsTest$LoadableDescriptorsTest1.class
68-
cls = ClassFile.read(NoUnnecessaryLoadableDescriptorsTest.class.getResourceAsStream("NoUnnecessaryLoadableDescriptorsTest$LoadableDescriptorsTest1.class"));
69-
70-
if (cls == null) {
71-
throw new AssertionError("Could not locate the class files");
71+
try (var in = NoUnnecessaryLoadableDescriptorsTest.class.getResourceAsStream("NoUnnecessaryLoadableDescriptorsTest$LoadableDescriptorsTest1.class")) {
72+
cls = ClassFile.of().parse(in.readAllBytes());
7273
}
7374

7475
/* Check emission of LoadableDescriptors attribute */
75-
LoadableDescriptors = (LoadableDescriptors_attribute) cls.attributes.get(Attribute.LoadableDescriptors);
76-
if (LoadableDescriptors != null) {
76+
if (cls.findAttribute(Attributes.loadableDescriptors()).isPresent()) {
7777
throw new AssertionError("Unexpected LoadableDescriptors attribute!");
7878
}
7979

80-
// There should be no LoadableDescriptors attribute in NoUnnecessaryLoadableDescriptorsTest$PreloadTest2.class
81-
cls = ClassFile.read(NoUnnecessaryLoadableDescriptorsTest.class.getResourceAsStream("NoUnnecessaryLoadableDescriptorsTest$LoadableDescriptorsTest2.class"));
82-
83-
if (cls == null) {
84-
throw new AssertionError("Could not locate the class files");
80+
// There should be no LoadableDescriptors attribute in NoUnnecessaryLoadableDescriptorsTest$LoadableDescriptorsTest2.class
81+
try (var in = NoUnnecessaryLoadableDescriptorsTest.class.getResourceAsStream("NoUnnecessaryLoadableDescriptorsTest$LoadableDescriptorsTest2.class")) {
82+
cls = ClassFile.of().parse(in.readAllBytes());
8583
}
8684

8785
/* Check emission of LoadableDescriptors attribute */
88-
LoadableDescriptors = (LoadableDescriptors_attribute) cls.attributes.get(Attribute.LoadableDescriptors);
89-
if (LoadableDescriptors != null) {
86+
if (cls.findAttribute(Attributes.loadableDescriptors()).isPresent()) {
9087
throw new AssertionError("Unexpected LoadableDescriptors attribute!");
9188
}
9289

9390
// There should be no LoadableDescriptors attribute in NoUnnecessaryLoadableDescriptorsTest$LoadableDescriptorsTest2$Inner2.class
94-
cls = ClassFile.read(NoUnnecessaryLoadableDescriptorsTest.class.getResourceAsStream("NoUnnecessaryLoadableDescriptorsTest$LoadableDescriptorsTest2$Inner1$Inner2.class"));
95-
96-
if (cls == null) {
97-
throw new AssertionError("Could not locate the class files");
91+
try (var in = NoUnnecessaryLoadableDescriptorsTest.class.getResourceAsStream("NoUnnecessaryLoadableDescriptorsTest$LoadableDescriptorsTest2$Inner1$Inner2.class")) {
92+
cls = ClassFile.of().parse(in.readAllBytes());
9893
}
9994

10095
/* Check emission of LoadableDescriptors attribute */
101-
LoadableDescriptors = (LoadableDescriptors_attribute) cls.attributes.get(Attribute.LoadableDescriptors);
102-
if (LoadableDescriptors != null) {
96+
if (cls.findAttribute(Attributes.loadableDescriptors()).isPresent()) {
10397
throw new AssertionError("Unexpected LoadableDescriptors attribute!");
10498
}
10599

106100
// There should be ONE LoadableDescriptors attribute entry in NoUnnecessaryLoadableDescriptorsTest$LoadableDescriptorsTest2$Inner1.class
107-
cls = ClassFile.read(NoUnnecessaryLoadableDescriptorsTest.class.getResourceAsStream("NoUnnecessaryLoadableDescriptorsTest$LoadableDescriptorsTest2$Inner1.class"));
101+
try (var in = NoUnnecessaryLoadableDescriptorsTest.class.getResourceAsStream("NoUnnecessaryLoadableDescriptorsTest$LoadableDescriptorsTest2$Inner1.class")) {
102+
cls = ClassFile.of().parse(in.readAllBytes());
103+
}
108104

109105
if (cls == null) {
110106
throw new AssertionError("Could not locate the class files");
111107
}
112108

113109
/* Check emission of LoadableDescriptors attribute */
114-
LoadableDescriptors = (LoadableDescriptors_attribute) cls.attributes.get(Attribute.LoadableDescriptors);
115-
if (LoadableDescriptors == null) {
116-
throw new AssertionError("Missing LoadableDescriptors attribute!");
117-
}
118-
119-
if (LoadableDescriptors.number_of_descriptors != 1) {
120-
throw new AssertionError("Incorrect number of LoadableDescriptors classes");
121-
}
110+
loadableDescriptors = cls.findAttribute(Attributes.loadableDescriptors()).orElseThrow();
122111

123-
CONSTANT_Utf8_info utf8Info = cls.constant_pool.getUTF8Info(LoadableDescriptors.descriptors[0]);
124-
System.err.println("utf8 " + utf8Info.value);
125-
if (!utf8Info.value.equals("LNoUnnecessaryLoadableDescriptorsTest$LoadableDescriptorsTest2$Inner1$Inner2;")) {
126-
throw new AssertionError("Expected LoadableDescriptors class entry is missing, but found " + utf8Info.value);
112+
List<String> expected = List.of("LNoUnnecessaryLoadableDescriptorsTest$LoadableDescriptorsTest2$Inner1$Inner2;");
113+
List<String> found = loadableDescriptors.loadableDescriptors().stream().map(Utf8Entry::stringValue).toList();
114+
if (!expected.equals(found)) {
115+
throw new AssertionError("Expected one LoadableDescriptors class entry Inner2, but found " + found);
127116
}
128117
}
129118
}

test/langtools/tools/javac/valhalla/value-objects/ValueBasedFlagsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2024, 2025, 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
@@ -37,12 +37,12 @@
3737
* @run main ValueBasedFlagsTest
3838
*/
3939

40+
import java.lang.classfile.ClassFile;
4041
import java.nio.file.Path;
4142
import java.nio.file.Paths;
4243

4344
import com.sun.tools.javac.code.Flags;
4445
import com.sun.tools.javac.util.Assert;
45-
import com.sun.tools.classfile.ClassFile;
4646

4747
import toolbox.TestRunner;
4848
import toolbox.ToolBox;
@@ -88,7 +88,7 @@ final class ValueBasedTest {}
8888
.run()
8989
.writeAll();
9090
Path classFilePath = classes.resolve("java", "lang", "ValueBasedTest.class");
91-
ClassFile classFile = ClassFile.read(classFilePath.toFile());
92-
Assert.check((classFile.access_flags.flags & Flags.ACC_STRICT) == 0);
91+
var classFile = ClassFile.of().parse(classFilePath);
92+
Assert.check((classFile.flags().flagsMask() & Flags.ACC_STRICT) == 0);
9393
}
9494
}

0 commit comments

Comments
 (0)