8212197: OpenDataException thrown when constructing CompositeData for StackTraceElement
authormchung
Tue, 16 Oct 2018 11:47:33 -0700
changeset 52152 bfdf2926cebc
parent 52151 af6fb2cb82ae
child 52153 3b17277860e7
8212197: OpenDataException thrown when constructing CompositeData for StackTraceElement Reviewed-by: alanb
src/java.management/share/classes/sun/management/StackTraceElementCompositeData.java
test/jdk/sun/management/StackTraceElementCompositeData/CompatibilityTest.java
--- a/src/java.management/share/classes/sun/management/StackTraceElementCompositeData.java	Tue Oct 16 11:24:41 2018 -0700
+++ b/src/java.management/share/classes/sun/management/StackTraceElementCompositeData.java	Tue Oct 16 11:47:33 2018 -0700
@@ -78,14 +78,16 @@
         // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
         // STACK_TRACE_ELEMENT_ATTRIBUTES!
         final Object[] stackTraceElementItemValues = {
-            ste.getClassLoaderName(),
-            ste.getModuleName(),
-            ste.getModuleVersion(),
+            // JDK 5 attributes
             ste.getClassName(),
             ste.getMethodName(),
             ste.getFileName(),
             ste.getLineNumber(),
             ste.isNativeMethod(),
+            // JDK 9 attributes
+            ste.getClassLoaderName(),
+            ste.getModuleName(),
+            ste.getModuleVersion(),
         };
         try {
             return new CompositeDataSupport(STACK_TRACE_ELEMENT_COMPOSITE_TYPE,
--- a/test/jdk/sun/management/StackTraceElementCompositeData/CompatibilityTest.java	Tue Oct 16 11:24:41 2018 -0700
+++ b/test/jdk/sun/management/StackTraceElementCompositeData/CompatibilityTest.java	Tue Oct 16 11:47:33 2018 -0700
@@ -36,7 +36,7 @@
 
 /*
  * @test
- * @bug     8139587
+ * @bug     8139587 8212197
  * @modules java.management/sun.management
  * @summary Check backward compatibility of StackTraceElementCompositeData
  * @author  Jaroslav Bachorik
@@ -154,5 +154,16 @@
         assertEquals(ste.isNativeMethod(), false);
         assertEquals(ste.getLineNumber(), 123);
     }
+
+    @Test
+    public void testCompositeData() throws Exception {
+        StackTraceElement ste = new StackTraceElement("app",
+                                                      "m", "1.0",
+                                                      "p.MyClass", "myMethod",
+                                                      "MyClass.java", 123);
+        CompositeData cd = StackTraceElementCompositeData.toCompositeData(ste);
+        StackTraceElement ste1 = StackTraceElementCompositeData.from(cd);
+        assertEquals(ste, ste1);
+    }
 }