HADOOP-12117. Potential NPE from Configuration#loadProperty with allowNullValueProperties set. (Contributed by zhihai xu)
This commit is contained in:
parent
af63427c6d
commit
99c8c5839b
@ -933,6 +933,9 @@ Release 2.8.0 - UNRELEASED
|
||||
HADOOP-12186. ActiveStandbyElector shouldn't call monitorLockNodeAsync
|
||||
multiple times (zhihai xu via vinayakumarb)
|
||||
|
||||
HADOOP-12117. Potential NPE from Configuration#loadProperty with
|
||||
allowNullValueProperties set. (zhihai xu via vinayakumarb)
|
||||
|
||||
Release 2.7.2 - UNRELEASED
|
||||
|
||||
INCOMPATIBLE CHANGES
|
||||
|
@ -2739,10 +2739,10 @@ private void overlay(Properties to, Properties from) {
|
||||
private void loadProperty(Properties properties, String name, String attr,
|
||||
String value, boolean finalParameter, String[] source) {
|
||||
if (value != null || allowNullValueProperties) {
|
||||
if (value == null) {
|
||||
value = DEFAULT_STRING_CHECK;
|
||||
}
|
||||
if (!finalParameters.contains(attr)) {
|
||||
if (value==null && allowNullValueProperties) {
|
||||
value = DEFAULT_STRING_CHECK;
|
||||
}
|
||||
properties.setProperty(attr, value);
|
||||
if(source != null) {
|
||||
updatingResource.put(attr, source);
|
||||
|
@ -42,6 +42,7 @@
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.hadoop.conf.Configuration.IntegerRanges;
|
||||
@ -49,6 +50,7 @@
|
||||
import org.apache.hadoop.io.IOUtils;
|
||||
import org.apache.hadoop.net.NetUtils;
|
||||
import static org.apache.hadoop.util.PlatformName.IBM_JAVA;
|
||||
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
@ -1511,6 +1513,19 @@ public void run() {
|
||||
// it's expected behaviour.
|
||||
}
|
||||
|
||||
public void testNullValueProperties() throws Exception {
|
||||
Configuration conf = new Configuration();
|
||||
conf.setAllowNullValueProperties(true);
|
||||
out = new BufferedWriter(new FileWriter(CONFIG));
|
||||
startConfig();
|
||||
appendProperty("attr", "value", true);
|
||||
appendProperty("attr", "", true);
|
||||
endConfig();
|
||||
Path fileResource = new Path(CONFIG);
|
||||
conf.addResource(fileResource);
|
||||
assertEquals("value", conf.get("attr"));
|
||||
}
|
||||
|
||||
public static void main(String[] argv) throws Exception {
|
||||
junit.textui.TestRunner.main(new String[]{
|
||||
TestConfiguration.class.getName()
|
||||
|
Loading…
Reference in New Issue
Block a user