geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [5/8] geode git commit: GEODE-2796: ClassPathLoader does not blow up with null TCCL
Date Thu, 20 Apr 2017 21:23:19 GMT
GEODE-2796: ClassPathLoader does not blow up with null TCCL


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

Branch: refs/heads/feature/GEODE-2632-5
Commit: 48d662aab7ae4110f36a05aadefe9c12b48c1293
Parents: aaef124
Author: Jared Stewart <jstewart@pivotal.io>
Authored: Tue Apr 18 14:08:19 2017 -0700
Committer: Jared Stewart <jstewart@pivotal.io>
Committed: Wed Apr 19 20:08:04 2017 -0700

----------------------------------------------------------------------
 .../apache/geode/internal/ClassPathLoader.java  | 10 +++++++--
 .../ClassPathLoaderIntegrationTest.java         | 22 +++++++++++++++++---
 2 files changed, 27 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/48d662aa/geode-core/src/main/java/org/apache/geode/internal/ClassPathLoader.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/ClassPathLoader.java b/geode-core/src/main/java/org/apache/geode/internal/ClassPathLoader.java
index 41cce05..39e9d62 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/ClassPathLoader.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/ClassPathLoader.java
@@ -32,6 +32,7 @@ import java.net.URLClassLoader;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
 
 /**
  * The delegating <tt>ClassLoader</tt> used by GemFire to load classes and other
resources. This
@@ -303,10 +304,15 @@ public final class ClassPathLoader {
     ArrayList<ClassLoader> classLoaders = new ArrayList<>();
 
     if (!excludeTCCL) {
-      classLoaders.add(Thread.currentThread().getContextClassLoader());
+      ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+      if (tccl != null) {
+        classLoaders.add(tccl);
+      }
     }
 
-    classLoaders.add(classLoaderForDeployedJars);
+    if (classLoaderForDeployedJars != null) {
+      classLoaders.add(classLoaderForDeployedJars);
+    }
 
     return classLoaders;
   }

http://git-wip-us.apache.org/repos/asf/geode/blob/48d662aa/geode-core/src/test/java/org/apache/geode/internal/ClassPathLoaderIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/ClassPathLoaderIntegrationTest.java
b/geode-core/src/test/java/org/apache/geode/internal/ClassPathLoaderIntegrationTest.java
index c783318..2a3a7dd 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/ClassPathLoaderIntegrationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/ClassPathLoaderIntegrationTest.java
@@ -91,6 +91,24 @@ public class ClassPathLoaderIntegrationTest {
     ClassPathLoader.setLatestToDefault(temporaryFolder.getRoot());
   }
 
+  @Test
+  public void testClassLoaderWithNullTccl() throws IOException, ClassNotFoundException {
+    // GEODE-2796
+    Thread.currentThread().setContextClassLoader(null);
+    String jarName = "JarDeployerIntegrationTest.jar";
+
+    String classAResource = "integration/parent/ClassA.class";
+
+    String classAName = "integration.parent.ClassA";
+
+    byte[] firstJarBytes = createJarWithClass("ClassA");
+
+    // First deploy of the JAR file
+    ClassPathLoader.getLatest().getJarDeployer().deploy(jarName, firstJarBytes).getFile();
+
+    assertThatClassCanBeLoaded(classAName);
+    assertThatResourceCanBeLoaded(classAResource);
+  }
 
   @Test
   public void testDeployFileAndChange() throws IOException, ClassNotFoundException {
@@ -258,13 +276,11 @@ public class ClassPathLoaderIntegrationTest {
     List<String> result = (List<String>) execution.execute("MyFunction").getResult();
     assertThat(result.get(0)).isEqualTo("Version1");
 
-
     ClassPathLoader.getLatest().getJarDeployer().deploy("MyJar.jar",
         FileUtils.readFileToByteArray(jarVersion2));
     result = (List<String>) execution.execute("MyFunction").getResult();
     assertThat(result.get(0)).isEqualTo("Version2");
 
-
     serverStarterRule.after();
   }
 
@@ -451,7 +467,7 @@ public class ClassPathLoaderIntegrationTest {
     /**
      * Currently unused but potentially useful for some future test. This causes this loader
to only
      * generate a class that the parent could not find.
-     *
+     * 
      * @param parent the parent class loader to check with first
      */
     @SuppressWarnings("unused")


Mime
View raw message