changeset 60210:a268c653f404

8223066: "jfr metadata" output the @Name annotation twice Reviewed-by: mgronlun, egahlin Contributed-by: erik.gahlin@oracle.com, chiroito107@gmail.com
author egahlin
date Tue, 25 Feb 2020 20:45:29 +0100
parents 9e359ab51ce6
children 16973c5b27be
files src/jdk.jfr/share/classes/jdk/jfr/internal/tool/PrettyWriter.java test/jdk/jdk/jfr/tool/TestMetadata.java
diffstat 2 files changed, 29 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/PrettyWriter.java	Thu Feb 20 20:56:49 2020 +0100
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/PrettyWriter.java	Tue Feb 25 20:45:29 2020 +0100
@@ -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.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 @@
 
     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();
+                }
             }
         }
     }
--- a/test/jdk/jdk/jfr/tool/TestMetadata.java	Thu Feb 20 20:56:49 2020 +0100
+++ b/test/jdk/jdk/jfr/tool/TestMetadata.java	Tue Feb 25 20:45:29 2020 +0100
@@ -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 @@
                 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++;
+        }
     }
 }