From f4fcd3882e1cda108404325ada685abd38cf210d Mon Sep 17 00:00:00 2001 From: Aljoscha Krettek Date: Mon, 4 Dec 2017 16:14:56 +0100 Subject: [PATCH] [FLINK-8186] Exclude flink-avro from flink-dist; fix AvroUtils loading Before, AvroUtils were loaded when the class was loaded which didn't take into account the user-code ClassLoader. Now, we try loading avro utils with the Thread context ClassLoader. --- .../flink/api/java/typeutils/AvroUtils.java | 18 ++++++------------ flink-dist/pom.xml | 10 ---------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/flink-core/src/main/java/org/apache/flink/api/java/typeutils/AvroUtils.java b/flink-core/src/main/java/org/apache/flink/api/java/typeutils/AvroUtils.java index 2983be0a7cf7e..0677338b7b2b9 100644 --- a/flink-core/src/main/java/org/apache/flink/api/java/typeutils/AvroUtils.java +++ b/flink-core/src/main/java/org/apache/flink/api/java/typeutils/AvroUtils.java @@ -37,12 +37,14 @@ public abstract class AvroUtils { private static final String AVRO_KRYO_UTILS = "org.apache.flink.formats.avro.utils.AvroKryoSerializerUtils"; - private static final AvroUtils INSTANCE = loadAvroKryoUtils(); - - private static AvroUtils loadAvroKryoUtils() { + /** + * Returns either the default {@link AvroUtils} which throw an exception in cases where Avro + * would be needed or loads the specific utils for Avro from flink-avro. + */ + public static AvroUtils getAvroUtils() { // try and load the special AvroUtils from the flink-avro package try { - Class clazz = Class.forName(AVRO_KRYO_UTILS, false, AvroUtils.class.getClassLoader()); + Class clazz = Class.forName(AVRO_KRYO_UTILS, false, Thread.currentThread().getContextClassLoader()); return clazz.asSubclass(AvroUtils.class).getConstructor().newInstance(); } catch (ClassNotFoundException e) { // cannot find the utils, return the default implementation @@ -52,14 +54,6 @@ private static AvroUtils loadAvroKryoUtils() { } } - /** - * Returns either the default {@link AvroUtils} which throw an exception in cases where Avro - * would be needed or loads the specific utils for Avro from flink-avro. - */ - public static AvroUtils getAvroUtils() { - return INSTANCE; - } - // ------------------------------------------------------------------------ /** diff --git a/flink-dist/pom.xml b/flink-dist/pom.xml index 95b244ca20e93..124481fdf172a 100644 --- a/flink-dist/pom.xml +++ b/flink-dist/pom.xml @@ -79,12 +79,6 @@ under the License. ${project.version} - - org.apache.flink - flink-avro - ${project.version} - - org.apache.flink flink-streaming-java_${scala.binary.version} @@ -497,10 +491,6 @@ under the License. - - org.codehaus.jackson - org.apache.flink.formats.avro.shaded.org.codehaus.jackson - com.fasterxml.jackson