diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index bcd48c4c55..0dbe5bc6f7 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -75,6 +75,8 @@ Trunk (unreleased changes) HADOOP-7886. Add toString to FileStatus. (SreeHari via jghoman) BUGS + HADOOP-7851. Configuration.getClasses() never returns the default value. + (amarrk) HADOOP-7606. Upgrade Jackson to version 1.7.1 to match the version required by Jersey (Alejandro Abdelnur via atm) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java index a3d4de0cb3..164128e14b 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java @@ -1145,9 +1145,11 @@ public Class getClassByName(String name) throws ClassNotFoundException { * or defaultValue. */ public Class[] getClasses(String name, Class ... defaultValue) { - String[] classnames = getTrimmedStrings(name); - if (classnames == null) + String valueString = getRaw(name); + if (null == valueString) { return defaultValue; + } + String[] classnames = getTrimmedStrings(name); try { Class[] classes = new Class[classnames.length]; for(int i = 0; i < classnames.length; i++) { diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java index f9f14fb848..68f19756a3 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java @@ -837,6 +837,27 @@ public void testGetValByRegex() { assertTrue("Picked out wrong key " + key4, !res.containsKey(key4)); } + public void testGetClassesShouldReturnDefaultValue() throws Exception { + Configuration config = new Configuration(); + Class[] classes = + config.getClasses("testClassName", Configuration.class); + assertEquals( + "Not returning expected number of classes. Number of returned classes =" + + classes.length, 1, classes.length); + assertEquals("Not returning the default class Name", Configuration.class, + classes[0]); + } + + public void testGetClassesShouldReturnEmptyArray() + throws Exception { + Configuration config = new Configuration(); + config.set("testClassName", ""); + Class[] classes = config.getClasses("testClassName", Configuration.class); + assertEquals( + "Not returning expected number of classes. Number of returned classes =" + + classes.length, 0, classes.length); + } + public static void main(String[] argv) throws Exception { junit.textui.TestRunner.main(new String[]{ TestConfiguration.class.getName()