HADOOP-7258. The Gzip codec should not return null decompressors. (omalley)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20-security-203@1099324 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/core/org/apache/hadoop/io/compress/DoNotPool.java b/src/core/org/apache/hadoop/io/compress/DoNotPool.java
index 71c5c21..8d1b64d 100644
--- a/src/core/org/apache/hadoop/io/compress/DoNotPool.java
+++ b/src/core/org/apache/hadoop/io/compress/DoNotPool.java
@@ -18,14 +18,17 @@
package org.apache.hadoop.io.compress;
import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
/**
* This is a marker annotation that marks a compressor or decompressor
* type as not to be pooled.
*/
@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
@Documented
public @interface DoNotPool {
diff --git a/src/core/org/apache/hadoop/io/compress/zlib/BuiltInGzipDecompressor.java b/src/core/org/apache/hadoop/io/compress/zlib/BuiltInGzipDecompressor.java
index a7d38b3..76611ec 100644
--- a/src/core/org/apache/hadoop/io/compress/zlib/BuiltInGzipDecompressor.java
+++ b/src/core/org/apache/hadoop/io/compress/zlib/BuiltInGzipDecompressor.java
@@ -31,6 +31,7 @@
* http://www.gzip.org/
*
*/
+@DoNotPool
public class BuiltInGzipDecompressor implements Decompressor {
private static final int GZIP_MAGIC_ID = 0x8b1f; // if read as LE short int
private static final int GZIP_DEFLATE_METHOD = 8;
@@ -109,7 +110,6 @@
/**
* Creates a new (pure Java) gzip decompressor.
*/
- @DoNotPool
public BuiltInGzipDecompressor() {
state = GzipStateLabel.HEADER_BASIC;
crc.reset();
diff --git a/src/test/org/apache/hadoop/io/compress/TestCodec.java b/src/test/org/apache/hadoop/io/compress/TestCodec.java
index 34422ad..98f6d50 100644
--- a/src/test/org/apache/hadoop/io/compress/TestCodec.java
+++ b/src/test/org/apache/hadoop/io/compress/TestCodec.java
@@ -475,31 +475,37 @@
assertTrue("ZlibFactory returned unexpected inflator",
zlibDecompressor instanceof BuiltInZlibInflater);
- // Asking for a decompressor directly from GzipCodec should return null;
// its createOutputStream() just wraps the existing stream in a
// java.util.zip.GZIPOutputStream.
CompressionCodecFactory ccf = new CompressionCodecFactory(conf);
CompressionCodec codec = ccf.getCodec(new Path("foo.gz"));
assertTrue("Codec for .gz file is not GzipCodec",
codec instanceof GzipCodec);
+
+ // make sure we don't get a null decompressor
Decompressor codecDecompressor = codec.createDecompressor();
if (null == codecDecompressor) {
fail("Got null codecDecompressor");
}
// Asking the CodecPool for a decompressor for GzipCodec
- // should return null as well.
+ // should not return null
Decompressor poolDecompressor = CodecPool.getDecompressor(codec);
if (null == poolDecompressor) {
- fail("Got null poolDecompressor: " + poolDecompressor);
+ fail("Got null poolDecompressor");
}
- // If we then ensure that the pool is populated...
+ // return a couple decompressors
CodecPool.returnDecompressor(zlibDecompressor);
- // return the decompressor
CodecPool.returnDecompressor(poolDecompressor);
Decompressor poolDecompressor2 = CodecPool.getDecompressor(codec);
- if (poolDecompressor == poolDecompressor2) {
- fail("Reused gzip decompressor in pool");
+ if (poolDecompressor.getClass() == BuiltInGzipDecompressor.class) {
+ if (poolDecompressor == poolDecompressor2) {
+ fail("Reused java gzip decompressor in pool");
+ }
+ } else {
+ if (poolDecompressor != poolDecompressor2) {
+ fail("Did not reuse native gzip decompressor in pool");
+ }
}
}