Forráskód Böngészése

commit e631bf277592a4e8a2f4f626672edebd0e00163b
Author: Mahadev Konar <mahadev@cdev6022.inktomisearch.com>
Date: Thu Feb 18 22:12:29 2010 +0000

HADOOP:6550 from http://issues.apache.org/jira/secure/attachment/12436045/c6560_20100212_y0.20.patch

+++ b/YAHOO-CHANGES.txt
+ HADOOP-6560. HarFileSystem throws NPE for har://hdfs-/foo (nicholas via
+ mahadev)
+


git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20-security-patches@1077175 13f79535-47bb-0310-9956-ffa450edef68

Owen O'Malley 14 éve
szülő
commit
9d2a0f19b1

+ 14 - 6
src/core/org/apache/hadoop/fs/HarFileSystem.java

@@ -181,12 +181,20 @@ public class HarFileSystem extends FilterFileSystem {
       return FileSystem.getDefaultUri(conf);
     }
     String host = rawURI.getHost();
-    String[] str = host.split("-", 2);
-    if (str[0] == null) {
-      throw new IOException("URI: " + rawURI + " is an invalid Har URI.");
-    }
-    String underLyingScheme = str[0];
-    String underLyingHost = (str.length > 1)? str[1]:null;
+    if (host == null) {
+      throw new IOException("URI: " + rawURI
+          + " is an invalid Har URI since host==null."
+          + "  Expecting har://<scheme>-<host>/<path>.");
+    }
+    int i = host.indexOf('-');
+    if (i < 0) {
+      throw new IOException("URI: " + rawURI
+          + " is an invalid Har URI since '-' not found."
+          + "  Expecting har://<scheme>-<host>/<path>.");
+    }
+    final String underLyingScheme = host.substring(0, i);
+    i++;
+    final String underLyingHost = i == host.length()? null: host.substring(i);
     int underLyingPort = rawURI.getPort();
     String auth = (underLyingHost == null && underLyingPort == -1)?
                   null:(underLyingHost+":"+underLyingPort);

+ 20 - 0
src/test/org/apache/hadoop/fs/TestHarFileSystem.java

@@ -294,4 +294,24 @@ public class TestHarFileSystem extends TestCase {
     assertTrue("number of bytes left should be -1", reduceIn.read(b) == -1);
     reduceIn.close();
   }
+
+  public void testHarUri() {
+    final Configuration conf = new Configuration();
+    checkInvalidPath("har://hdfs-/foo.har", conf);
+    checkInvalidPath("har://hdfs/foo.har", conf);
+    checkInvalidPath("har://-hdfs/foo.har", conf);
+    checkInvalidPath("har://-/foo.har", conf);
+  }
+
+  static void checkInvalidPath(String s, Configuration conf) {
+    System.out.println("\ncheckInvalidPath: " + s);
+    final Path p = new Path(s);
+    try {
+      p.getFileSystem(conf);
+      fail(p + " is an invalid path.");
+    } catch (IOException e) {
+      System.out.println("GOOD: Got an exception.");
+      e.printStackTrace(System.out);
+    }
+  }
 }