You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by tr...@apache.org on 2018/07/04 09:59:28 UTC
[2/2] flink git commit: [FLINK-9654] Changed the way we check if a
class is anonymous to avoid SI-2034.
[FLINK-9654] Changed the way we check if a class is anonymous to avoid SI-2034.
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/7ca0fd78
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/7ca0fd78
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/7ca0fd78
Branch: refs/heads/master
Commit: 7ca0fd783eb2ec01a0011eb891db75d998d635f4
Parents: 579807d
Author: Zsolt Donca <zs...@8x8.com>
Authored: Mon Jun 25 10:43:29 2018 +0300
Committer: Till Rohrmann <tr...@apache.org>
Committed: Wed Jul 4 11:57:01 2018 +0200
----------------------------------------------------------------------
.../apache/flink/util/InstantiationUtil.java | 22 ++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/7ca0fd78/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java b/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java
index 3db0236..2370c7c 100644
--- a/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java
+++ b/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java
@@ -208,10 +208,7 @@ public final class InstantiationUtil {
final Class localClass = resolveClass(streamClassDescriptor);
final String name = localClass.getName();
- if (scalaSerializerClassnames.contains(name) || scalaTypes.contains(name) || localClass.isAnonymousClass()
- // isAnonymousClass does not work for anonymous Scala classes; additionally check by classname
- || name.contains("$anon$") || name.contains("$anonfun")) {
-
+ if (scalaSerializerClassnames.contains(name) || scalaTypes.contains(name) || isAnonymousClass(localClass)) {
final ObjectStreamClass localClassDescriptor = ObjectStreamClass.lookup(localClass);
if (localClassDescriptor != null
&& localClassDescriptor.getSerialVersionUID() != streamClassDescriptor.getSerialVersionUID()) {
@@ -226,6 +223,23 @@ public final class InstantiationUtil {
}
}
+ private static boolean isAnonymousClass(Class clazz) {
+ final String name = clazz.getName();
+
+ // isAnonymousClass does not work for anonymous Scala classes; additionally check by class name
+ if (name.contains("$anon$") || name.contains("$anonfun") || name.contains("$macro$")) {
+ return true;
+ }
+
+ // calling isAnonymousClass or getSimpleName can throw InternalError for certain Scala types, see https://issues.scala-lang.org/browse/SI-2034
+ // until we move to JDK 9, this try-catch is necessary
+ try {
+ return clazz.isAnonymousClass();
+ } catch (InternalError e) {
+ return false;
+ }
+ }
+
/**
* A mapping between the full path of a deprecated serializer and its equivalent.
* These mappings are hardcoded and fixed.