diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index befa1c86c1d..207378f6850 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -35,6 +35,9 @@ Release 2.0.1-alpha - UNRELEASED HADOOP-8400. All commands warn "Kerberos krb5 configuration not found" when security is not enabled. (tucu) + HADOOP-8406. CompressionCodecFactory.CODEC_PROVIDERS iteration is + thread-unsafe (todd) + Release 2.0.0-alpha - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/CompressionCodecFactory.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/CompressionCodecFactory.java index e12dcfeeb4a..dc95e9e999d 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/CompressionCodecFactory.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/CompressionCodecFactory.java @@ -109,8 +109,12 @@ public class CompressionCodecFactory { List> result = new ArrayList>(); // Add codec classes discovered via service loading - for (CompressionCodec codec : CODEC_PROVIDERS) { - result.add(codec.getClass()); + synchronized (CODEC_PROVIDERS) { + // CODEC_PROVIDERS is a lazy collection. Synchronize so it is + // thread-safe. See HADOOP-8406. + for (CompressionCodec codec : CODEC_PROVIDERS) { + result.add(codec.getClass()); + } } // Add codec classes from configuration String codecsString = conf.get("io.compression.codecs");