You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by el...@apache.org on 2010/06/09 19:57:49 UTC

svn commit: r953100 - in /hadoop/common/trunk: CHANGES.txt src/java/org/apache/hadoop/fs/FileStatus.java src/test/core/org/apache/hadoop/fs/TestFileStatus.java

Author: eli
Date: Wed Jun  9 17:57:49 2010
New Revision: 953100

URL: http://svn.apache.org/viewvc?rev=953100&view=rev
Log:
HADOOP-6796. FileStatus allows null srcPath but crashes if that's done. Contributed by Rodrigo Schmidt.

Added:
    hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFileStatus.java
Modified:
    hadoop/common/trunk/CHANGES.txt
    hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileStatus.java

Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=953100&r1=953099&r2=953100&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Wed Jun  9 17:57:49 2010
@@ -76,6 +76,8 @@ Trunk (unreleased changes)
     HADOOP-6687.   user object in the subject in UGI should be reused in case 
     of a relogin. (jnp via boryas)
 
+    HADOOP-6796. FileStatus allows null srcPath but crashes if that's done. (Rodrigo Schmidt via eli)
+
 Release 0.21.0 - Unreleased
 
   INCOMPATIBLE CHANGES

Modified: hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileStatus.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileStatus.java?rev=953100&r1=953099&r2=953100&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileStatus.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileStatus.java Wed Jun  9 17:57:49 2010
@@ -29,19 +29,19 @@ import org.apache.hadoop.io.Writable;
  */
 public class FileStatus implements Writable, Comparable {
 
-  private Path path;
-  private long length;
-  private boolean isdir;
-  private short block_replication;
-  private long blocksize;
-  private long modification_time;
-  private long access_time;
-  private FsPermission permission;
-  private String owner;
-  private String group;
-  private Path symlink;
+  private Path path = null;
+  private long length = 0;
+  private boolean isdir = false;
+  private short block_replication = 0;
+  private long blocksize = 0;
+  private long modification_time = 0;
+  private long access_time = 0;
+  private FsPermission permission = null;
+  private String owner = null;
+  private String group = null;
+  private Path symlink = null;
   
-  public FileStatus() { this(0, false, 0, 0, 0, 0, null, null, null, null); }
+  public FileStatus() {}
   
   //We should deprecate this soon?
   public FileStatus(long length, boolean isdir, int block_replication,
@@ -63,6 +63,12 @@ public class FileStatus implements Writa
          access_time, permission, owner, group, null, path);
   }
 
+  private void stateSanityCheck() {
+    if (path == null) {
+      throw new IllegalArgumentException("path cannot be null");
+    }
+  }
+
   public FileStatus(long length, boolean isdir,
                     int block_replication,
                     long blocksize, long modification_time, long access_time,
@@ -81,6 +87,7 @@ public class FileStatus implements Writa
     this.group = (group == null) ? "" : group;
     this.symlink = symlink;
     this.path = path;
+    stateSanityCheck();
   }
 
   /**

Added: hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFileStatus.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFileStatus.java?rev=953100&view=auto
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFileStatus.java (added)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFileStatus.java Wed Jun  9 17:57:49 2010
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.fs;
+
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+import org.apache.hadoop.fs.permission.FsPermission;
+
+public class TestFileStatus {
+
+  @Test
+  public void testFileStatusNullPath() throws Exception {
+
+    new FileStatus();
+    new FileStatus(1,false,3,3,4, new Path("/"));  new FileStatus(1,false,5,3,4,5,null,null,null,new Path("/a/b"));
+    new FileStatus(1,false,5,3,4,5,null,null,null,null,new Path("/a/b"));
+    new FileStatus(1,false,5,3,4,5,new FsPermission((short) 7),
+            "bla","bla",new Path ("/b/c"), new Path("/a/b"));
+
+    boolean error = false;
+    try{
+        new FileStatus(1,false,3,3,4, null);
+    } catch (IllegalArgumentException exc) {
+        error = true;
+    }
+
+    assertTrue("Accepted null path", error);
+
+    try {
+      new FileStatus(1,false,5,3,4,5,null,null,null,null);
+    } catch (IllegalArgumentException exc) {
+      error = true;
+    }
+
+    assertTrue("Accepted null path",error);
+
+    try {
+      new FileStatus(1,false,5,3,4,5,null,null,null,null,null);
+    } catch (IllegalArgumentException exc) {
+      error = true;
+    }
+
+    assertTrue("Accepted null path",error);
+
+    try {
+      new FileStatus(1,false,5,3,4,5,new FsPermission((short) 7),
+          "bla","bla",new Path ("/b/c"), null);
+    } catch (IllegalArgumentException exc) {
+      error = true;
+    }
+
+    assertTrue("Accepted null path",error);
+
+  }
+}