From c4870fb505474d7ed67da27e2eed9063bb7c09c1 Mon Sep 17 00:00:00 2001 From: "Taro L. Saito" Date: Mon, 1 Aug 2011 13:43:12 +0900 Subject: [PATCH 1/2] Report exception message correctly --- src/main/java/org/xerial/snappy/SnappyLoader.java | 2 +- src/test/java/org/xerial/snappy/SnappyLoaderTest.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/xerial/snappy/SnappyLoader.java b/src/main/java/org/xerial/snappy/SnappyLoader.java index 22d96e1..f802183 100755 --- a/src/main/java/org/xerial/snappy/SnappyLoader.java +++ b/src/main/java/org/xerial/snappy/SnappyLoader.java @@ -194,7 +194,7 @@ public class SnappyLoader throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY, ee.getMessage()); } catch (Exception e2) { - throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY, e.getMessage()); + throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY, e2.getMessage()); } } catch (Exception e) { diff --git a/src/test/java/org/xerial/snappy/SnappyLoaderTest.java b/src/test/java/org/xerial/snappy/SnappyLoaderTest.java index 87663b6..db862f7 100755 --- a/src/test/java/org/xerial/snappy/SnappyLoaderTest.java +++ b/src/test/java/org/xerial/snappy/SnappyLoaderTest.java @@ -82,6 +82,13 @@ public class SnappyLoaderTest ClassLoader parent = this.getClass().getClassLoader().getParent(); ClassWorld cw = new ClassWorld(); ClassRealm P = cw.newRealm("P", parent); + try { + P.loadClass("org.xerial.snappy.Snappy"); + fail("org.xerial.snappy.Snappy is found in the parent"); + } + catch (ClassNotFoundException e) { + // OK + } // Prepare the child class loaders which can load Snappy.class URL classPath = new File("target/classes").toURI().toURL(); From 75e34c87171dfe1cd790329e595f942910661461 Mon Sep 17 00:00:00 2001 From: "Taro L. Saito" Date: Mon, 1 Aug 2011 13:57:47 +0900 Subject: [PATCH 2/2] Wrap native code loading part with synchornized block --- .../java/org/xerial/snappy/SnappyLoader.java | 2 +- .../xerial/snappy/SnappyNativeLoader.bytecode | Bin 1179 -> 1179 bytes .../org/xerial/snappy/SnappyNativeLoader.java | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/xerial/snappy/SnappyLoader.java b/src/main/java/org/xerial/snappy/SnappyLoader.java index f802183..bf4c9e8 100755 --- a/src/main/java/org/xerial/snappy/SnappyLoader.java +++ b/src/main/java/org/xerial/snappy/SnappyLoader.java @@ -112,7 +112,7 @@ public class SnappyLoader return isLoaded; } - static SnappyNativeAPI load() { + static synchronized SnappyNativeAPI load() { if (isInitialized) return api; diff --git a/src/main/resources/org/xerial/snappy/SnappyNativeLoader.bytecode b/src/main/resources/org/xerial/snappy/SnappyNativeLoader.bytecode index 93bdcce8b0286ef2e383d5243a2659c44f6b49fe..64c0fe86a245d6ee88b1b8a84c0042c7389da0ee 100755 GIT binary patch delta 19 ZcmbQuIh%7sC^Mtx loadedLibFiles = new HashMap(); private static HashMap loadedLib = new HashMap(); - public static void load(String lib) { + public static synchronized void load(String lib) { if (loadedLibFiles.containsKey(lib) && loadedLibFiles.get(lib) == true) return; @@ -44,7 +44,7 @@ public class SnappyNativeLoader } } - public static void loadLibrary(String libname) { + public static synchronized void loadLibrary(String libname) { if (loadedLib.containsKey(libname) && loadedLib.get(libname) == true) return;