Skip to content

Commit

Permalink
[FLINK-35887][core] Fix NPE in TypeExtractor where getSuperclass from…
Browse files Browse the repository at this point in the history
… an interface returns null

This closes #25801
  • Loading branch information
dylanhz authored Dec 16, 2024
1 parent 61b1c33 commit 5c9c45c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2224,7 +2224,9 @@ protected <OUT, IN1, IN2> TypeInformation<OUT> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -64,4 +78,14 @@ public static class Pojo {
public static class PojoRequiringKryo {
public List<Integer> x;
}

@TypeInfo(FooFactory.class)
public interface Foo {}

public static class FooFactory extends TypeInfoFactory<Foo> {
@Override
public TypeInformation<Foo> createTypeInfo(Type type, Map<String, TypeInformation<?>> map) {
return Types.POJO(Foo.class, new HashMap<>());
}
}
}

0 comments on commit 5c9c45c

Please sign in to comment.