diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSStripedInputStream.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSStripedInputStream.java index d4d06465c7b..e7d90edf37c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSStripedInputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSStripedInputStream.java @@ -68,7 +68,7 @@ public class DFSStripedInputStream extends DFSInputStream { private ByteBuffer curStripeBuf; private ByteBuffer parityBuf; private final ErasureCodingPolicy ecPolicy; - private final RawErasureDecoder decoder; + private RawErasureDecoder decoder; /** * Indicate the start/end offset of the current buffered stripe in the @@ -188,7 +188,10 @@ public class DFSStripedInputStream extends DFSInputStream { BUFFER_POOL.putBuffer(parityBuf); parityBuf = null; } - decoder.release(); + if (decoder != null) { + decoder.release(); + decoder = null; + } } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSStripedInputStream.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSStripedInputStream.java index f94b7abeee2..de276a9e698 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSStripedInputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSStripedInputStream.java @@ -491,4 +491,17 @@ public class TestDFSStripedInputStream { assertEquals(readSize, done); assertArrayEquals(expected, readBuffer); } + + @Test + public void testIdempotentClose() throws Exception { + final int numBlocks = 2; + DFSTestUtil.createStripedFile(cluster, filePath, null, numBlocks, + stripesPerBlock, false, ecPolicy); + + try (DFSInputStream in = fs.getClient().open(filePath.toString())) { + assertTrue(in instanceof DFSStripedInputStream); + // Close twice + in.close(); + } + } }