8255560: Class::isRecord should check that the current class is final and not abstract

Reviewed-by: mchung, darcy
This commit is contained in:
Chris Hegarty 2020-12-07 11:02:52 +00:00
parent 8e8e584552
commit 5a03e47605
3 changed files with 227 additions and 22 deletions

View file

@ -3662,9 +3662,10 @@ public final class Class<T> implements java.io.Serializable,
* Returns {@code true} if and only if this class is a record class.
*
* <p> The {@linkplain #getSuperclass() direct superclass} of a record
* class is {@code java.lang.Record}. A record class has (possibly zero)
* record components, that is, {@link #getRecordComponents()} returns a
* non-null value.
* class is {@code java.lang.Record}. A record class is {@linkplain
* Modifier#FINAL final}. A record class has (possibly zero) record
* components; {@link #getRecordComponents()} returns a non-null but
* possibly empty value for a record.
*
* <p> Note that class {@link Record} is not a record type and thus invoking
* this method on class {@code Record} returns {@code false}.
@ -3674,7 +3675,9 @@ public final class Class<T> implements java.io.Serializable,
* @since 16
*/
public boolean isRecord() {
return getSuperclass() == java.lang.Record.class && isRecord0();
return getSuperclass() == java.lang.Record.class &&
(this.getModifiers() & Modifier.FINAL) != 0 &&
isRecord0();
}
// Fetches the factory for reflective objects