JDK 14 RFR of JDK-8235369: "Class.toGenericString need to be updated for records"
Vicente Romero
vicente.romero at oracle.com
Thu Dec 5 20:41:25 UTC 2019
looks good,
Vicente
On 12/5/19 1:08 PM, Joe Darcy wrote:
> Hello,
>
> Please review this small cleanup to records support in java.lang.Class:
>
> JDK-8235369: "Class.toGenericString need to be updated for records"
> CSR: https://bugs.openjdk.java.net/browse/JDK-8235428
> webrev: http://cr.openjdk.java.net/~darcy/8235369.0/
>
> Patch below; thanks,
>
> -Joe
>
> diff -r 666fa504b60c src/java.base/share/classes/java/lang/Class.java
> --- a/src/java.base/share/classes/java/lang/Class.java Wed Dec 04
> 14:55:15 2019 -0800
> +++ b/src/java.base/share/classes/java/lang/Class.java Thu Dec 05
> 10:04:26 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>@</code>{@code interface}, as appropriate), followed
> + * and {@code class}, {@code enum}, {@code interface},
> + * <code>@</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");
> }
>
> diff -r 666fa504b60c
> test/jdk/java/lang/reflect/records/RecordReflectionTest.java
> --- a/test/jdk/java/lang/reflect/records/RecordReflectionTest.java Wed
> Dec 04 14:55:15 2019 -0800
> +++ b/test/jdk/java/lang/reflect/records/RecordReflectionTest.java Thu
> Dec 05 10:05:01 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() {
>
>
More information about the core-libs-dev
mailing list