hadoop-hdfs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1102091 - in /hadoop/hdfs/branches/branch-0.22: CHANGES.txt src/java/org/apache/hadoop/hdfs/DFSInputStream.java src/test/hdfs/org/apache/hadoop/hdfs/TestDistributedFileSystem.java
Date Wed, 11 May 2011 21:11:35 GMT
Author: todd
Date: Wed May 11 21:11:34 2011
New Revision: 1102091

URL: http://svn.apache.org/viewvc?rev=1102091&view=rev
Log:
HDFS-1615. seek() on closed DFS input stream throws NullPointerException. Contributed by Scott
Carey.

Modified:
    hadoop/hdfs/branches/branch-0.22/CHANGES.txt
    hadoop/hdfs/branches/branch-0.22/src/java/org/apache/hadoop/hdfs/DFSInputStream.java
    hadoop/hdfs/branches/branch-0.22/src/test/hdfs/org/apache/hadoop/hdfs/TestDistributedFileSystem.java

Modified: hadoop/hdfs/branches/branch-0.22/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hdfs/branches/branch-0.22/CHANGES.txt?rev=1102091&r1=1102090&r2=1102091&view=diff
==============================================================================
--- hadoop/hdfs/branches/branch-0.22/CHANGES.txt (original)
+++ hadoop/hdfs/branches/branch-0.22/CHANGES.txt Wed May 11 21:11:34 2011
@@ -496,6 +496,9 @@ Release 0.22.0 - Unreleased
     HDFS-1544. Ivy resolve force mode should be turned off by default.
     (Luke Lu via tomwhite)
 
+    HDFS-1615. seek() on closed DFS input stream throws NullPointerException
+    (Scott Carey via todd)
+
 Release 0.21.1 - Unreleased
 
   IMPROVEMENTS

Modified: hadoop/hdfs/branches/branch-0.22/src/java/org/apache/hadoop/hdfs/DFSInputStream.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/branches/branch-0.22/src/java/org/apache/hadoop/hdfs/DFSInputStream.java?rev=1102091&r1=1102090&r2=1102091&view=diff
==============================================================================
--- hadoop/hdfs/branches/branch-0.22/src/java/org/apache/hadoop/hdfs/DFSInputStream.java (original)
+++ hadoop/hdfs/branches/branch-0.22/src/java/org/apache/hadoop/hdfs/DFSInputStream.java Wed
May 11 21:11:34 2011
@@ -736,6 +736,9 @@ public class DFSInputStream extends FSIn
     if (targetPos > getFileLength()) {
       throw new IOException("Cannot seek after EOF");
     }
+    if (closed) {
+      throw new IOException("Stream is closed!");
+    }
     boolean done = false;
     if (pos <= targetPos && targetPos <= blockEnd) {
       //

Modified: hadoop/hdfs/branches/branch-0.22/src/test/hdfs/org/apache/hadoop/hdfs/TestDistributedFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/branches/branch-0.22/src/test/hdfs/org/apache/hadoop/hdfs/TestDistributedFileSystem.java?rev=1102091&r1=1102090&r2=1102091&view=diff
==============================================================================
--- hadoop/hdfs/branches/branch-0.22/src/test/hdfs/org/apache/hadoop/hdfs/TestDistributedFileSystem.java
(original)
+++ hadoop/hdfs/branches/branch-0.22/src/test/hdfs/org/apache/hadoop/hdfs/TestDistributedFileSystem.java
Wed May 11 21:11:34 2011
@@ -96,6 +96,45 @@ public class TestDistributedFileSystem {
       if (cluster != null) {cluster.shutdown();}
     }
   }
+  
+  @Test
+  public void testDFSSeekExceptions() throws IOException {
+    Configuration conf = getTestConfiguration();
+    MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
+    FileSystem fileSys = cluster.getFileSystem();
+
+    try {
+      String file = "/test/fileclosethenseek/file-0";
+      Path path = new Path(file);
+      // create file
+      FSDataOutputStream output = fileSys.create(path);
+      output.writeBytes("Some test data to write longer than 10 bytes");
+      output.close();
+      FSDataInputStream input = fileSys.open(path);
+      input.seek(10);
+      boolean threw = false;
+      try {
+        input.seek(100);
+      } catch (IOException e) {
+        // success
+        threw = true;
+      }
+      assertTrue("Failed to throw IOE when seeking past end", threw);
+      input.close();
+      threw = false;
+      try {
+        input.seek(1);
+      } catch (IOException e) {
+        //success
+        threw = true;
+      }
+      assertTrue("Failed to throw IOE when seeking after close", threw);
+      fileSys.close();
+    }
+    finally {
+      if (cluster != null) {cluster.shutdown();}
+    }
+  }
 
   @Test
   public void testDFSClient() throws Exception {



Mime
View raw message