diff --git a/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java b/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java index fd7978d323542..5b4fce8b22150 100644 --- a/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java +++ b/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java @@ -2224,7 +2224,9 @@ protected TypeInformation analyzePojo( */ @PublicEvolving public static boolean isRecord(Class clazz) { - return clazz.getSuperclass().getName().equals("java.lang.Record") + Class superclass = clazz.getSuperclass(); + return superclass != null + && superclass.getName().equals("java.lang.Record") && (clazz.getModifiers() & Modifier.FINAL) != 0; } diff --git a/flink-test-utils-parent/flink-test-utils/src/test/java/org/apache/flink/types/PojoTestUtilsTest.java b/flink-test-utils-parent/flink-test-utils/src/test/java/org/apache/flink/types/PojoTestUtilsTest.java index 6d9f399ea7809..506124816b1da 100644 --- a/flink-test-utils-parent/flink-test-utils/src/test/java/org/apache/flink/types/PojoTestUtilsTest.java +++ b/flink-test-utils-parent/flink-test-utils/src/test/java/org/apache/flink/types/PojoTestUtilsTest.java @@ -17,9 +17,17 @@ package org.apache.flink.types; +import org.apache.flink.api.common.typeinfo.TypeInfo; +import org.apache.flink.api.common.typeinfo.TypeInfoFactory; +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.common.typeinfo.Types; + import org.junit.jupiter.api.Test; +import java.lang.reflect.Type; +import java.util.HashMap; import java.util.List; +import java.util.Map; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -41,6 +49,12 @@ void testPojoAcceptedIfKryoRequired() { PojoTestUtils.assertSerializedAsPojo(PojoRequiringKryo.class); } + @Test + void testPojoTypeInfoOnInterface() { + // reported in FLINK-35887 + PojoTestUtils.assertSerializedAsPojo(Foo.class); + } + @Test void testWithoutKryoPojoAccepted() { PojoTestUtils.assertSerializedAsPojoWithoutKryo(Pojo.class); @@ -64,4 +78,14 @@ public static class Pojo { public static class PojoRequiringKryo { public List x; } + + @TypeInfo(FooFactory.class) + public interface Foo {} + + public static class FooFactory extends TypeInfoFactory { + @Override + public TypeInformation createTypeInfo(Type type, Map> map) { + return Types.POJO(Foo.class, new HashMap<>()); + } + } }