You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2016/01/18 09:39:16 UTC

[2/4] ignite git commit: IGNITE-2342: Set correct classlader before calling FileSystem.get().

IGNITE-2342: Set correct classlader before calling FileSystem.get().


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

Branch: refs/heads/master
Commit: ca0f79e69ed39def0b6aa7611d9b3eaa1c7fba39
Parents: 122d27c
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Fri Jan 8 10:23:55 2016 +0400
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Mon Jan 18 11:35:53 2016 +0300

----------------------------------------------------------------------
 .../hadoop/fs/BasicHadoopFileSystemFactory.java  | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ca0f79e6/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/BasicHadoopFileSystemFactory.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/BasicHadoopFileSystemFactory.java b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/BasicHadoopFileSystemFactory.java
index 1e2bbf2..c791e9a 100644
--- a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/BasicHadoopFileSystemFactory.java
+++ b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/BasicHadoopFileSystemFactory.java
@@ -80,7 +80,24 @@ public class BasicHadoopFileSystemFactory implements HadoopFileSystemFactory, Ex
         assert cfg != null;
 
         try {
-            return FileSystem.get(fullUri, cfg, usrName);
+            // FileSystem.get() might delegate to ServiceLoader to get the list of file system implementation.
+            // And ServiceLoader is known to be sensitive to context classloader. Therefore, we change context
+            // classloader to classloader of current class to avoid strange class-cast-exceptions.
+            ClassLoader ctxClsLdr = Thread.currentThread().getContextClassLoader();
+            ClassLoader clsLdr = getClass().getClassLoader();
+
+            if (ctxClsLdr == clsLdr)
+                return FileSystem.get(fullUri, cfg, usrName);
+            else {
+                Thread.currentThread().setContextClassLoader(clsLdr);
+
+                try {
+                    return FileSystem.get(fullUri, cfg, usrName);
+                }
+                finally {
+                    Thread.currentThread().setContextClassLoader(ctxClsLdr);
+                }
+            }
         }
         catch (InterruptedException e) {
             Thread.currentThread().interrupt();