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 to...@apache.org on 2009/05/27 12:31:48 UTC

svn commit: r779093 - in /hadoop/core/trunk: CHANGES.txt src/hdfs/org/apache/hadoop/hdfs/server/namenode/INode.java src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestINode.java

Author: tomwhite
Date: Wed May 27 10:31:47 2009
New Revision: 779093

URL: http://svn.apache.org/viewvc?rev=779093&view=rev
Log:
HADOOP-5700. INode.getPathComponents throws NPE when given a non-absolute path. Contributed by Todd Lipcon.

Added:
    hadoop/core/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestINode.java
Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/namenode/INode.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=779093&r1=779092&r2=779093&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Wed May 27 10:31:47 2009
@@ -692,6 +692,9 @@
     HADOOP-5635. Change distributed cache to work with other distributed file
     systems. (Andrew Hitchcock via tomwhite)
 
+    HADOOP-5700. INode.getPathComponents throws NPE when given a non-absolute
+    path. (Todd Lipcon via tomwhite)
+
 Release 0.20.1 - Unreleased
 
   INCOMPATIBLE CHANGES

Modified: hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/namenode/INode.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/namenode/INode.java?rev=779093&r1=779092&r2=779093&view=diff
==============================================================================
--- hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/namenode/INode.java (original)
+++ hadoop/core/trunk/src/hdfs/org/apache/hadoop/hdfs/server/namenode/INode.java Wed May 27 10:31:47 2009
@@ -309,11 +309,15 @@
 
   /**
    * Breaks file path into components.
-   * @param path
+   * @param path an absolute path on the file system
    * @return array of byte arrays each of which represents 
    * a single path component.
    */
   static byte[][] getPathComponents(String path) {
+    if (!path.startsWith("/")) {
+      throw new IllegalArgumentException(
+        "Must pass an absolute path to getPathComponents");
+    }
     return getPathComponents(getPathNames(path));
   }
 

Added: hadoop/core/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestINode.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestINode.java?rev=779093&view=auto
==============================================================================
--- hadoop/core/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestINode.java (added)
+++ hadoop/core/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestINode.java Wed May 27 10:31:47 2009
@@ -0,0 +1,45 @@
+/**
+ * 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.hdfs.server.namenode;
+
+import junit.framework.TestCase;
+import static org.junit.Assert.*;
+
+public class TestINode extends TestCase {
+  public void testPathNames() {
+    assertArrayEquals(new String[]{"", "foo", "bar"},
+                      INode.getPathNames("/foo/bar"));
+    assertArrayEquals(new String[]{"", "foo"},
+                      INode.getPathNames("/foo"));
+
+    byte[][] comps = INode.getPathComponents("/foo/bar");
+    assertEquals(3, comps.length);
+    assertArrayEquals("".getBytes(), comps[0]);
+    assertArrayEquals("foo".getBytes(), comps[1]);
+    assertArrayEquals("bar".getBytes(), comps[2]);
+
+    boolean thrown = false;
+    try {
+      INode.getPathComponents("foo");
+    } catch (IllegalArgumentException iae) {
+      thrown = true;
+    }
+    assertTrue(thrown);
+  }
+}
\ No newline at end of file