You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by mjsax <gi...@git.apache.org> on 2015/12/15 14:58:56 UTC

[GitHub] flink pull request: Set current class loader to user-class loader ...

GitHub user mjsax opened a pull request:

    https://github.com/apache/flink/pull/1457

    Set current class loader to user-class loader and disable class initialization.

    This PR fixes class loading issues with regard to Clojure. It is required to execute a Clojure example via `bin/flink run`.
    
    The Clojure example can be found here: https://github.com/mjsax/flink-external/tree/master/flink-clojure

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/mjsax/flink clojureClassLoadingFix

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/flink/pull/1457.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1457
    
----
commit 6b0464cc27b348664c754a27c2e6f4024bd039a9
Author: mjsax <mj...@informatik.hu-berlin.de>
Date:   2015-12-15T13:14:17Z

    Set current class loader to user-class loader and disable class initialization.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: Set current class loader to user-class loader ...

Posted by StephanEwen <gi...@git.apache.org>.
Github user StephanEwen commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1457#discussion_r48012762
  
    --- Diff: flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java ---
    @@ -574,8 +574,11 @@ private static String getEntryPointClassNameFromJar(URL jarFile) throws ProgramI
     	}
     	
     	private static Class<?> loadMainClass(String className, ClassLoader cl) throws ProgramInvocationException {
    +		ClassLoader contextCl = null;
     		try {
    -			return Class.forName(className, true, cl);
    +			contextCl = Thread.currentThread().getContextClassLoader();
    +			Thread.currentThread().setContextClassLoader(cl);
    +			return Class.forName(className, false, cl);
    --- End diff --
    
    Seems fair. Looks good to me then!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: Set current class loader to user-class loader ...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/flink/pull/1457


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: Set current class loader to user-class loader ...

Posted by mjsax <gi...@git.apache.org>.
Github user mjsax commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1457#discussion_r47919597
  
    --- Diff: flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java ---
    @@ -574,8 +574,11 @@ private static String getEntryPointClassNameFromJar(URL jarFile) throws ProgramI
     	}
     	
     	private static Class<?> loadMainClass(String className, ClassLoader cl) throws ProgramInvocationException {
    +		ClassLoader contextCl = null;
     		try {
    -			return Class.forName(className, true, cl);
    +			contextCl = Thread.currentThread().getContextClassLoader();
    +			Thread.currentThread().setContextClassLoader(cl);
    +			return Class.forName(className, false, cl);
    --- End diff --
    
    Required for the Clojure case. If we initialize right here, the `main` method gets invoked right away. This is too early as not everything got set up properly at this point by the client and the execution fails.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: Set current class loader to user-class loader ...

Posted by StephanEwen <gi...@git.apache.org>.
Github user StephanEwen commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1457#discussion_r47918946
  
    --- Diff: flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java ---
    @@ -574,8 +574,11 @@ private static String getEntryPointClassNameFromJar(URL jarFile) throws ProgramI
     	}
     	
     	private static Class<?> loadMainClass(String className, ClassLoader cl) throws ProgramInvocationException {
    +		ClassLoader contextCl = null;
     		try {
    -			return Class.forName(className, true, cl);
    +			contextCl = Thread.currentThread().getContextClassLoader();
    +			Thread.currentThread().setContextClassLoader(cl);
    +			return Class.forName(className, false, cl);
    --- End diff --
    
    Why set initialization to `false` here?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: Set current class loader to user-class loader ...

Posted by StephanEwen <gi...@git.apache.org>.
Github user StephanEwen commented on the pull request:

    https://github.com/apache/flink/pull/1457#issuecomment-165484795
  
    Good catch!
    
    The context class loaded needs to set where ever we reflectively invoke user code. We simply forgot it at that place...
    
    +1 to merge


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: Set current class loader to user-class loader ...

Posted by mjsax <gi...@git.apache.org>.
Github user mjsax commented on the pull request:

    https://github.com/apache/flink/pull/1457#issuecomment-164794316
  
    Personal Travis is green: https://travis-ci.org/mjsax/flink/builds/96973608


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---