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
This commit is contained in:
parent
2eb39c55d6
commit
385f31ad85
|
@ -254,6 +254,10 @@ Branch-2 ( Unreleased changes )
|
|||
|
||||
HADOOP-8541. Better high-percentile latency metrics. (Andrew Wang via atm)
|
||||
|
||||
HADOOP-8362. Improve exception message when Configuration.set() is
|
||||
called with a null key or value. (Madhukara Phatak
|
||||
and Suresh Srinivas via harsh)
|
||||
|
||||
BUG FIXES
|
||||
|
||||
HADOOP-8372. NetUtils.normalizeHostName() incorrectly handles hostname
|
||||
|
|
|
@ -84,6 +84,7 @@ import org.w3c.dom.Node;
|
|||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Text;
|
||||
import org.xml.sax.SAXException;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
/**
|
||||
* Provides access to configuration parameters.
|
||||
|
@ -781,8 +782,15 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
|||
* @param value property value.
|
||||
* @param source the place that this configuration value came from
|
||||
* (For debugging).
|
||||
* @throws IllegalArgumentException when the value or name is null.
|
||||
*/
|
||||
public void set(String name, String value, String source) {
|
||||
Preconditions.checkArgument(
|
||||
name != null,
|
||||
"Property name must not be null");
|
||||
Preconditions.checkArgument(
|
||||
value != null,
|
||||
"Property value must not be null");
|
||||
if (deprecatedKeyMap.isEmpty()) {
|
||||
getProps();
|
||||
}
|
||||
|
|
|
@ -1065,6 +1065,26 @@ public class TestConfiguration extends TestCase {
|
|||
"Not returning expected number of classes. Number of returned classes ="
|
||||
+ classes.length, 0, classes.length);
|
||||
}
|
||||
|
||||
public void testSettingValueNull() throws Exception {
|
||||
Configuration config = new Configuration();
|
||||
try {
|
||||
config.set("testClassName", null);
|
||||
fail("Should throw an IllegalArgumentException exception ");
|
||||
} catch (Exception e) {
|
||||
assertTrue(e instanceof IllegalArgumentException);
|
||||
}
|
||||
}
|
||||
|
||||
public void testSettingKeyNull() throws Exception {
|
||||
Configuration config = new Configuration();
|
||||
try {
|
||||
config.set(null, "test");
|
||||
fail("Should throw an IllegalArgumentException exception ");
|
||||
} catch (Exception e) {
|
||||
assertTrue(e instanceof IllegalArgumentException);
|
||||
}
|
||||
}
|
||||
|
||||
public void testInvalidSubstitutation() {
|
||||
String key = "test.random.key";
|
||||
|
|
Loading…
Reference in New Issue