flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From twal...@apache.org
Subject flink git commit: [FLINK-4872] [types] Type erasure problem exclusively on cluster execution
Date Mon, 28 Nov 2016 17:28:52 GMT
Repository: flink
Updated Branches:
  refs/heads/master 60a4ab32e -> 3a27f55cf


[FLINK-4872] [types] Type erasure problem exclusively on cluster execution

This closes #2823.


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/3a27f55c
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/3a27f55c
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/3a27f55c

Branch: refs/heads/master
Commit: 3a27f55cfa03a96cb7aff5d25a6402a283be7b45
Parents: 60a4ab3
Author: twalthr <twalthr@apache.org>
Authored: Thu Nov 17 14:17:23 2016 +0100
Committer: twalthr <twalthr@apache.org>
Committed: Mon Nov 28 18:28:18 2016 +0100

----------------------------------------------------------------------
 .../flink/api/java/typeutils/TypeExtractor.java | 64 ++------------------
 1 file changed, 4 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/3a27f55c/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java
----------------------------------------------------------------------
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 b41bbc1..08f8c53 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
@@ -751,24 +751,9 @@ public class TypeExtractor {
 			
 			// due to a Java 6 bug, it is possible that the JVM classifies e.g. String[] or int[]
as GenericArrayType instead of Class
 			if (componentType instanceof Class) {
-				
 				Class<?> componentClass = (Class<?>) componentType;
-				String className;
-				// for int[], double[] etc.
-				if(componentClass.isPrimitive()) {
-					className = encodePrimitiveClass(componentClass);
-				}
-				// for String[], Integer[] etc.
-				else {
-					className = "L" + componentClass.getName() + ";";
-				}
-				
-				Class<OUT> classArray;
-				try {
-					classArray = (Class<OUT>) Class.forName("[" + className);
-				} catch (ClassNotFoundException e) {
-					throw new InvalidTypesException("Could not convert GenericArrayType to Class.");
-				}
+
+				Class<OUT> classArray = (Class<OUT>) (java.lang.reflect.Array.newInstance(componentClass,
0).getClass());
 
 				return getForClass(classArray);
 			} else {
@@ -778,21 +763,8 @@ public class TypeExtractor {
 					in1Type,
 					in2Type);
 
-				Class<OUT> classArray;
-
-				try {
-					String componentClassName = componentInfo.getTypeClass().getName();
-					String resultingClassName;
-
-					if (componentClassName.startsWith("[")) {
-						resultingClassName = "[" + componentClassName;
-					} else {
-						resultingClassName = "[L" + componentClassName + ";";
-					}
-					classArray = (Class<OUT>) Class.forName(resultingClassName);
-				} catch (ClassNotFoundException e) {
-					throw new InvalidTypesException("Could not convert GenericArrayType to Class.");
-				}
+				Class<?> componentClass = componentInfo.getTypeClass();
+				Class<OUT> classArray = (Class<OUT>) (java.lang.reflect.Array.newInstance(componentClass,
0).getClass());
 
 				return ObjectArrayTypeInfo.getInfoFor(classArray, componentInfo);
 			}
@@ -1559,34 +1531,6 @@ public class TypeExtractor {
 					+ "See the documentation for more information about how to compile jobs containing lambda
expressions.");
 		}
 	}
-	
-	private static String encodePrimitiveClass(Class<?> primitiveClass) {
-		if (primitiveClass == boolean.class) {
-			return "Z";
-		}
-		else if (primitiveClass == byte.class) {
-			return "B";
-		}
-		else if (primitiveClass == char.class) {
-			return "C";
-		}
-		else if (primitiveClass == double.class) {
-			return "D";
-		}
-		else if (primitiveClass == float.class) {
-			return "F";
-		}
-		else if (primitiveClass == int.class) {
-			return "I";
-		}
-		else if (primitiveClass == long.class) {
-			return "J";
-		}
-		else if (primitiveClass == short.class) {
-			return "S";
-		}
-		throw new InvalidTypesException();
-	}
 
 	/**
 	 * Tries to find a concrete value (Class, ParameterizedType etc. ) for a TypeVariable by
traversing the type hierarchy downwards.


Mime
View raw message