8223066: "jfr metadata" output the @Name annotation twice

Co-authored-by: Chihiro Ito <chiroito107@gmail.com>
Reviewed-by: mgronlun, egahlin
This commit is contained in:
Erik Gahlin 2020-02-25 20:45:29 +01:00
parent 53ee0c4963
commit dd8dbb66eb
2 changed files with 29 additions and 11 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -37,6 +37,7 @@ import jdk.jfr.AnnotationElement;
import jdk.jfr.DataAmount;
import jdk.jfr.Frequency;
import jdk.jfr.MemoryAddress;
import jdk.jfr.Name;
import jdk.jfr.Percentage;
import jdk.jfr.ValueDescriptor;
import jdk.jfr.consumer.RecordedClass;
@ -143,15 +144,17 @@ public final class PrettyWriter extends EventPrintWriter {
private void printAnnotations(int commentIndex, List<AnnotationElement> annotations) {
for (AnnotationElement a : annotations) {
printIndent();
print("@");
print(makeSimpleType(a.getTypeName()));
List<ValueDescriptor> vs = a.getValueDescriptors();
if (!vs.isEmpty()) {
printAnnotation(a);
printCommentRef(commentIndex, a.getTypeId());
} else {
println();
if (!Name.class.getName().equals(a.getTypeName())) {
printIndent();
print("@");
print(makeSimpleType(a.getTypeName()));
List<ValueDescriptor> vs = a.getValueDescriptors();
if (!vs.isEmpty()) {
printAnnotation(a);
printCommentRef(commentIndex, a.getTypeId());
} else {
println();
}
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,6 +26,8 @@
package jdk.jfr.tool;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Set;
import jdk.jfr.EventType;
import jdk.jfr.consumer.RecordingFile;
@ -59,5 +61,18 @@ public class TestMetadata {
output.shouldContain(name);
}
}
Set<String> annotations = new HashSet<>();
int lineNumber = 1;
for (String line : output.asLines()) {
if (line.startsWith("@")) {
if (annotations.contains(line)) {
throw new Exception("Line " + lineNumber + ":" + line + " repeats annotation");
}
annotations.add(line);
} else {
annotations.clear();
}
lineNumber++;
}
}
}