ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [2/5] ignite git commit: IGNITE-2342: Set correct classlader before calling FileSystem.get().
Date Fri, 08 Jan 2016 08:47:54 GMT
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/6ab4ce24
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6ab4ce24
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6ab4ce24

Branch: refs/heads/ignite-1.5.3
Commit: 6ab4ce246316442fa4295f9941c372fea70c24ef
Parents: c786820
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Fri Jan 8 10:23:55 2016 +0400
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Fri Jan 8 10:23:55 2016 +0400

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


http://git-wip-us.apache.org/repos/asf/ignite/blob/6ab4ce24/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();


Mime
View raw message