From 14bd82872dac0a7b6de487b1c71a332dabfe4243 Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Thu, 9 Jun 2011 22:34:32 +0000 Subject: [PATCH] HBASE-3871 Compression.java uses ClassLoader.getSystemClassLoader() to load codec git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1134119 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ .../hadoop/hbase/io/hfile/Compression.java | 22 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index ec60c012b0b..2c27d24a3b1 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -115,6 +115,8 @@ Release 0.91.0 - Unreleased HBASE-3894 Thread contention over row locks set monitor (Dave Latham) HBASE-3959 hadoop-snappy version in the pom.xml is incorrect (Alejandro Abdelnur) + HBASE-3971 Compression.java uses ClassLoader.getSystemClassLoader() + to load codec (Alejandro Abdelnur) IMPROVEMENTS HBASE-3290 Max Compaction Size (Nicolas Spiegelberg via Stack) diff --git a/src/main/java/org/apache/hadoop/hbase/io/hfile/Compression.java b/src/main/java/org/apache/hadoop/hbase/io/hfile/Compression.java index 4d04b66eba8..c0de5fc07e8 100644 --- a/src/main/java/org/apache/hadoop/hbase/io/hfile/Compression.java +++ b/src/main/java/org/apache/hadoop/hbase/io/hfile/Compression.java @@ -70,6 +70,24 @@ public final class Compression { } } + /** + * Returns the classloader to load the Codec class from. + * @return + */ + private static ClassLoader getClassLoaderForCodec() { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + if (cl == null) { + cl = Compression.class.getClassLoader(); + } + if (cl == null) { + cl = ClassLoader.getSystemClassLoader(); + } + if (cl == null) { + throw new RuntimeException("A ClassLoader to load the Codec could not be determined"); + } + return cl; + } + /** * Compression algorithms. The ordinal of these cannot change or else you * risk breaking all existing HFiles out there. Even the ones that are @@ -85,7 +103,7 @@ public final class Compression { if (lzoCodec == null) { try { Class externalCodec = - ClassLoader.getSystemClassLoader().loadClass("com.hadoop.compression.lzo.LzoCodec"); + getClassLoaderForCodec().loadClass("com.hadoop.compression.lzo.LzoCodec"); lzoCodec = (CompressionCodec) ReflectionUtils.newInstance(externalCodec, new Configuration(conf)); } catch (ClassNotFoundException e) { @@ -150,7 +168,7 @@ public final class Compression { if (snappyCodec == null) { try { Class externalCodec = - ClassLoader.getSystemClassLoader().loadClass("org.apache.hadoop.io.compress.SnappyCodec"); + getClassLoaderForCodec().loadClass("org.apache.hadoop.io.compress.SnappyCodec"); snappyCodec = (CompressionCodec) ReflectionUtils.newInstance(externalCodec, conf); } catch (ClassNotFoundException e) {