Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
HDFS-2358. NPE when the default filesystem's uri has no authority. Co…
Browse files Browse the repository at this point in the history
…ntributed by Daryn Sharp.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20-security-205@1179472 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mattf-apache committed Oct 5, 2011
1 parent 4a47846 commit d4d6649
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Expand Up @@ -56,6 +56,9 @@ Release 0.20.205.0 - 2011.09.28

BUG FIXES

HDFS-2358. NPE when the default filesystem's uri has no authority.
(Daryn Sharp via mattf)

MAPREDUCE-3112. Calling hadoop cli inside mapreduce job leads to errors.
(Eric Yang via mattf)

Expand Down
Expand Up @@ -223,7 +223,7 @@ public static InetSocketAddress getServiceAddress(Configuration conf,
}

public static InetSocketAddress getAddress(Configuration conf) {
return getAddress(FileSystem.getDefaultUri(conf).getAuthority());
return getAddress(FileSystem.getDefaultUri(conf).toString());
}

public static URI getUri(InetSocketAddress namenode) {
Expand Down
41 changes: 38 additions & 3 deletions src/test/org/apache/hadoop/hdfs/TestDefaultNameNodePort.java
Expand Up @@ -17,7 +17,9 @@
*/
package org.apache.hadoop.hdfs;

import junit.framework.TestCase;
import org.junit.*;
import static org.junit.Assert.*;

import java.io.*;
import java.net.*;
import java.util.*;
Expand All @@ -27,8 +29,8 @@
import org.apache.hadoop.hdfs.server.namenode.NameNode;

/** Test NameNode port defaulting code. */
public class TestDefaultNameNodePort extends TestCase {

public class TestDefaultNameNodePort {
@Test
public void testGetAddressFromString() throws Exception {
assertEquals(NameNode.getAddress("foo").getPort(),
NameNode.DEFAULT_PORT);
Expand All @@ -40,6 +42,7 @@ public void testGetAddressFromString() throws Exception {
555);
}

@Test
public void testGetAddressFromConf() throws Exception {
Configuration conf = new Configuration();
FileSystem.setDefaultUri(conf, "hdfs://foo/");
Expand All @@ -57,4 +60,36 @@ public void testGetUri() {
NameNode.DEFAULT_PORT)),
URI.create("hdfs://foo"));
}

@Test
public void testSlashAddress() throws Exception {
verifyBadAuthAddress("/junk");
}

@Test
public void testSlashSlashAddress() throws Exception {
verifyBadAuthAddress("//junk");
}

@Test
public void testNoAuthAddress() throws Exception {
// this is actually the default value if the default fs isn't configured!
verifyBadAuthAddress("file:///");
}

public void verifyBadAuthAddress(String noAuth) throws Exception {
Configuration conf = new Configuration();
FileSystem.setDefaultUri(conf, noAuth);
try {
InetSocketAddress addr = NameNode.getAddress(conf);
// this will show what we got back in case the test fails
assertEquals(null, addr);
} catch (IllegalArgumentException e) {
assertEquals(
"Does not contain a valid host:port authority: " + noAuth,
e.getMessage());
}
}


}

0 comments on commit d4d6649

Please sign in to comment.