beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (BEAM-682) Invoker Class should be created in Thread Context Classloader
Date Sat, 13 Jan 2018 06:59:00 GMT

    [ https://issues.apache.org/jira/browse/BEAM-682?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16325014#comment-16325014
] 

ASF GitHub Bot commented on BEAM-682:
-------------------------------------

jbonofre closed pull request #4235: [BEAM-682] try to define generated classes in the correct
classloader instead of the beam classloader by default
URL: https://github.com/apache/beam/pull/4235
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/ByteBuddyDoFnInvokerFactory.java
b/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/ByteBuddyDoFnInvokerFactory.java
index 8ce33483171..55ecda2ab92 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/ByteBuddyDoFnInvokerFactory.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/ByteBuddyDoFnInvokerFactory.java
@@ -18,6 +18,7 @@
 package org.apache.beam.sdk.transforms.reflect;
 
 import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.beam.sdk.util.common.ReflectHelpers.findClassLoader;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
@@ -326,7 +327,7 @@ public static RestrictionTracker invokeNewTracker(Object restriction)
{
         (Class<? extends DoFnInvoker<?, ?>>)
             unloaded
                 .load(
-                    ByteBuddyDoFnInvokerFactory.class.getClassLoader(),
+                    findClassLoader(fnClass.getClassLoader()),
                     ClassLoadingStrategy.Default.INJECTION)
                 .getLoaded();
     return res;
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/ByteBuddyOnTimerInvokerFactory.java
b/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/ByteBuddyOnTimerInvokerFactory.java
index 5e31f2e3e84..c5ef4b4a820 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/ByteBuddyOnTimerInvokerFactory.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/ByteBuddyOnTimerInvokerFactory.java
@@ -18,6 +18,8 @@
 package org.apache.beam.sdk.transforms.reflect;
 
 
+import static org.apache.beam.sdk.util.common.ReflectHelpers.findClassLoader;
+
 import com.google.common.base.CharMatcher;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
@@ -174,7 +176,7 @@ private ByteBuddyOnTimerInvokerFactory() {}
         (Class<? extends OnTimerInvoker<?, ?>>)
             unloaded
                 .load(
-                    ByteBuddyOnTimerInvokerFactory.class.getClassLoader(),
+                    findClassLoader(fnClass.getClassLoader()),
                     ClassLoadingStrategy.Default.INJECTION)
                 .getLoaded();
     return res;
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/common/ReflectHelpers.java
b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/common/ReflectHelpers.java
index 7752b2afde4..5c0fcdd61e1 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/common/ReflectHelpers.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/common/ReflectHelpers.java
@@ -223,12 +223,12 @@ public int compare(Object o1, Object o2) {
 
   /**
    * Finds the appropriate {@code ClassLoader} to be used by the
-   * {@link ServiceLoader#load} call, which by default would use the context
+   * {@link ServiceLoader#load} call, which by default would use the proposed
    * {@code ClassLoader}, which can be null. The fallback is as follows: context
    * ClassLoader, class ClassLoader and finaly the system ClassLoader.
    */
-  public static ClassLoader findClassLoader() {
-    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+  public static ClassLoader findClassLoader(final ClassLoader proposed) {
+    ClassLoader classLoader = proposed;
     if (classLoader == null) {
       classLoader = ReflectHelpers.class.getClassLoader();
     }
@@ -237,4 +237,14 @@ public static ClassLoader findClassLoader() {
     }
     return classLoader;
   }
+
+  /**
+   * Finds the appropriate {@code ClassLoader} to be used by the
+   * {@link ServiceLoader#load} call, which by default would use the context
+   * {@code ClassLoader}, which can be null. The fallback is as follows: context
+   * ClassLoader, class ClassLoader and finaly the system ClassLoader.
+   */
+  public static ClassLoader findClassLoader() {
+    return findClassLoader(Thread.currentThread().getContextClassLoader());
+  }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Invoker Class should be created in Thread Context Classloader
> -------------------------------------------------------------
>
>                 Key: BEAM-682
>                 URL: https://issues.apache.org/jira/browse/BEAM-682
>             Project: Beam
>          Issue Type: Bug
>          Components: sdk-java-core
>    Affects Versions: 0.3.0-incubating
>            Reporter: Sumit Chawla
>            Assignee: Sumit Chawla
>
> As of now the InvokerClass is being loaded in wrong classloader. It should be loaded
into Thread.currentThread.getContextClassLoader()
> https://github.com/apache/incubator-beam/blob/master/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/DoFnInvokers.java#L167
> {code}
>  Class<? extends DoFnInvoker<?, ?>> res =
>         (Class<? extends DoFnInvoker<?, ?>>)
>             unloaded
>                 .load(DoFnInvokers.class.getClassLoader(), ClassLoadingStrategy.Default.INJECTION)
>                 .getLoaded();
> {code}
> Fix 
> {code}
>  Class<? extends DoFnInvoker<?, ?>> res =
>         (Class<? extends DoFnInvoker<?, ?>>)
>             unloaded
>                 .load(Thread.currentThread().getContextClassLoader(),
>                         ClassLoadingStrategy.Default.INJECTION)
>                 .getLoaded();
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message