changeset 57252:dda989866962

8235369: Class.toGenericString need to be updated for records Reviewed-by: vromero, mchung, chegar
author darcy
date Thu, 05 Dec 2019 14:19:35 -0800
parents 20dfe7974cc2
children 0bec2ec012fc
files src/java.base/share/classes/java/lang/Class.java test/jdk/java/lang/reflect/records/RecordReflectionTest.java
diffstat 2 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/Class.java	Thu Dec 05 14:14:06 2019 -0800
+++ b/src/java.base/share/classes/java/lang/Class.java	Thu Dec 05 14:19:35 2019 -0800
@@ -207,8 +207,8 @@
      *
      * The string is formatted as a list of type modifiers, if any,
      * followed by the kind of type (empty string for primitive types
-     * and {@code class}, {@code enum}, {@code interface}, or
-     * <code>&#64;</code>{@code interface}, as appropriate), followed
+     * and {@code class}, {@code enum}, {@code interface},
+     * <code>&#64;</code>{@code interface}, or {@code record} as appropriate), followed
      * by the type's name, followed by an angle-bracketed
      * comma-separated list of the type's type parameters, if any,
      * including informative bounds on the type parameters, if any.
@@ -234,6 +234,7 @@
      *
      * @since 1.8
      */
+    @SuppressWarnings("preview")
     public String toGenericString() {
         if (isPrimitive()) {
             return toString();
@@ -264,6 +265,8 @@
                 } else {
                     if (isEnum())
                         sb.append("enum");
+                    else if (isRecord())
+                        sb.append("record");
                     else
                         sb.append("class");
                 }
--- a/test/jdk/java/lang/reflect/records/RecordReflectionTest.java	Thu Dec 05 14:14:06 2019 -0800
+++ b/test/jdk/java/lang/reflect/records/RecordReflectionTest.java	Thu Dec 05 14:19:35 2019 -0800
@@ -23,6 +23,7 @@
 
 /*
  * @test
+ * @bug 8235369
  * @summary reflection test for records
  * @compile --enable-preview -source ${jdk.version} RecordReflectionTest.java
  * @run testng/othervm --enable-preview RecordReflectionTest
@@ -51,8 +52,11 @@
     public void testIsRecord() {
         assertFalse(NoRecord.class.isRecord());
 
-        for (Class<?> c : List.of(R1.class, R2.class, R3.class))
-            assertTrue(c.isRecord());
+        for (Class<?> c : List.of(R1.class, R2.class, R3.class)) {
+            String message = c.toGenericString();
+            assertTrue(c.isRecord(), message);
+            assertTrue(message.contains("record") , message);
+        }
     }
 
     public void testGetComponentsNoRecord() {