Skip to content

Commit

Permalink
[FLINK-1471][java-api] Fixes wrong input validation if function has n…
Browse files Browse the repository at this point in the history
…o generics

This closes #359
  • Loading branch information
twalthr committed Feb 5, 2015
1 parent 4046819 commit d033fa8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
Expand Up @@ -680,10 +680,20 @@ private static void validateInputType(Type t, TypeInformation<?> inType) {
} }
} }


private static void validateInputType(Class<?> baseClass, Class<?> clazz, int inputParamPos, TypeInformation<?> inType) { private static void validateInputType(Class<?> baseClass, Class<?> clazz, int inputParamPos, TypeInformation<?> inTypeInfo) {
ArrayList<Type> typeHierarchy = new ArrayList<Type>(); ArrayList<Type> typeHierarchy = new ArrayList<Type>();

// try to get generic parameter
Type inType;
try {
inType = getParameterType(baseClass, typeHierarchy, clazz, inputParamPos);
}
catch (IllegalArgumentException e) {
return; // skip input validation e.g. for raw types
}

try { try {
validateInfo(typeHierarchy, getParameterType(baseClass, typeHierarchy, clazz, inputParamPos), inType); validateInfo(typeHierarchy, inType, inTypeInfo);
} }
catch(InvalidTypesException e) { catch(InvalidTypesException e) {
throw new InvalidTypesException("Input mismatch: " + e.getMessage()); throw new InvalidTypesException("Input mismatch: " + e.getMessage());
Expand Down
Expand Up @@ -1731,8 +1731,31 @@ public CustomType[][][] map(
+ ">>>", ti.toString()); + ">>>", ti.toString());


// generic array // generic array
// TODO depends on #315 ti = TypeExtractor.getMapReturnTypes((MapFunction) new MapperWithMultiDimGenericArray<String>(), TypeInfoParser.parse("String[][][]"));
//ti = TypeExtractor.getMapReturnTypes((MapFunction) new MapperWithMultiDimGenericArray<String>(), TypeInfoParser.parse("String[][][]")); Assert.assertEquals("ObjectArrayTypeInfo<ObjectArrayTypeInfo<ObjectArrayTypeInfo<Java Tuple1<String>>>>", ti.toString());
//Assert.assertEquals("ObjectArrayTypeInfo<ObjectArrayTypeInfo<ObjectArrayTypeInfo<Java Tuple1<String>>>>",); }

@SuppressWarnings("rawtypes")
public static class MapWithResultTypeQueryable implements MapFunction, ResultTypeQueryable {
private static final long serialVersionUID = 1L;

@Override
public TypeInformation getProducedType() {
return BasicTypeInfo.STRING_TYPE_INFO;
}

@Override
public Object map(Object value) throws Exception {
return null;
}
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testInputMismatchWithRawFuntion() {
MapFunction<?, ?> function = new MapWithResultTypeQueryable();

TypeInformation<?> ti = TypeExtractor.getMapReturnTypes((MapFunction)function, BasicTypeInfo.INT_TYPE_INFO);
Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, ti);
} }
} }

0 comments on commit d033fa8

Please sign in to comment.