Skip to content

Commit 3dcd96f

Browse files
committed
HADOOP-8362. Improve exception message when Configuration.set() is called with a null key or value. Contributed by Madhukara Phatak and Suresh Srinivas (harsh)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1361712 13f79535-47bb-0310-9956-ffa450edef68
1 parent e7312b1 commit 3dcd96f

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

hadoop-common-project/hadoop-common/CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ Branch-2 ( Unreleased changes )
254254

255255
HADOOP-8541. Better high-percentile latency metrics. (Andrew Wang via atm)
256256

257+
HADOOP-8362. Improve exception message when Configuration.set() is
258+
called with a null key or value. (Madhukara Phatak
259+
and Suresh Srinivas via harsh)
260+
257261
BUG FIXES
258262

259263
HADOOP-8372. NetUtils.normalizeHostName() incorrectly handles hostname

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
import org.w3c.dom.NodeList;
8585
import org.w3c.dom.Text;
8686
import org.xml.sax.SAXException;
87+
import com.google.common.base.Preconditions;
8788

8889
/**
8990
* Provides access to configuration parameters.
@@ -781,8 +782,15 @@ public void set(String name, String value) {
781782
* @param value property value.
782783
* @param source the place that this configuration value came from
783784
* (For debugging).
785+
* @throws IllegalArgumentException when the value or name is null.
784786
*/
785787
public void set(String name, String value, String source) {
788+
Preconditions.checkArgument(
789+
name != null,
790+
"Property name must not be null");
791+
Preconditions.checkArgument(
792+
value != null,
793+
"Property value must not be null");
786794
if (deprecatedKeyMap.isEmpty()) {
787795
getProps();
788796
}

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,26 @@ public void testGetClassesShouldReturnEmptyArray()
10651065
"Not returning expected number of classes. Number of returned classes ="
10661066
+ classes.length, 0, classes.length);
10671067
}
1068+
1069+
public void testSettingValueNull() throws Exception {
1070+
Configuration config = new Configuration();
1071+
try {
1072+
config.set("testClassName", null);
1073+
fail("Should throw an IllegalArgumentException exception ");
1074+
} catch (Exception e) {
1075+
assertTrue(e instanceof IllegalArgumentException);
1076+
}
1077+
}
1078+
1079+
public void testSettingKeyNull() throws Exception {
1080+
Configuration config = new Configuration();
1081+
try {
1082+
config.set(null, "test");
1083+
fail("Should throw an IllegalArgumentException exception ");
1084+
} catch (Exception e) {
1085+
assertTrue(e instanceof IllegalArgumentException);
1086+
}
1087+
}
10681088

10691089
public void testInvalidSubstitutation() {
10701090
String key = "test.random.key";

0 commit comments

Comments
 (0)