2014-10-24 09:54:04 +00:00
|
|
|
/*
|
2015-08-26 09:14:28 +00:00
|
|
|
* @test /nodynamiccopyright/
|
2014-10-24 09:54:04 +00:00
|
|
|
* @bug 8061778
|
|
|
|
* @summary Wrong LineNumberTable for default constructors
|
2023-12-04 07:07:57 +00:00
|
|
|
* @enablePreview
|
2014-10-24 09:54:04 +00:00
|
|
|
*/
|
|
|
|
|
2023-09-07 15:37:25 +00:00
|
|
|
import java.util.List;
|
2023-12-04 07:07:57 +00:00
|
|
|
import java.lang.classfile.*;
|
|
|
|
import java.lang.classfile.attribute.*;
|
2014-10-24 09:54:04 +00:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
public class NestedLineNumberTest {
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
2023-09-07 15:37:25 +00:00
|
|
|
List<LineNumberInfo> lines = findEntries();
|
|
|
|
if (lines == null || lines.size() != 1) {
|
|
|
|
int found = lines == null ? 0 : lines.size();
|
2014-10-24 09:54:04 +00:00
|
|
|
error(String.format("LineNumberTable contains wrong number of entries - expected %d, found %d", 1, found));
|
|
|
|
}
|
|
|
|
|
2023-09-07 15:37:25 +00:00
|
|
|
int line = lines.get(0).lineNumber();
|
2023-12-04 07:07:57 +00:00
|
|
|
if (line != 50) {
|
|
|
|
error(String.format("LineNumberTable contains wrong line number - expected %d, found %d", 50, line));
|
2014-10-24 09:54:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-07 15:37:25 +00:00
|
|
|
static List<LineNumberInfo> findEntries() throws IOException {
|
2023-12-04 07:07:57 +00:00
|
|
|
ClassModel self = ClassFile.of().parse(NestedLineNumberTest.Test.class.getResourceAsStream("NestedLineNumberTest$Test.class").readAllBytes());
|
2023-09-07 15:37:25 +00:00
|
|
|
for (MethodModel m : self.methods()) {
|
|
|
|
if ("<init>".equals(m.methodName().stringValue())) {
|
2024-05-24 15:58:34 +00:00
|
|
|
CodeAttribute code_attribute = m.findAttribute(Attributes.code()).orElseThrow();
|
2023-09-07 15:37:25 +00:00
|
|
|
for (Attribute<?> at : code_attribute.attributes()) {
|
|
|
|
if (at instanceof LineNumberTableAttribute lineAt) {
|
|
|
|
return lineAt.lineNumbers();
|
2014-10-24 09:54:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void error(String msg) {
|
|
|
|
throw new AssertionError(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The default constructor in this class should get only one LineNumberTable entry,
|
|
|
|
// pointing to the first line of the declaration of class Test.
|
|
|
|
static class Test {
|
|
|
|
static class Empty { }
|
|
|
|
}
|
|
|
|
}
|