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
|
HADOOP-12186. ActiveStandbyElector shouldn't call monitorLockNodeAsync
|
||||||
multiple times (zhihai xu via vinayakumarb)
|
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
|
Release 2.7.2 - UNRELEASED
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
@ -2739,10 +2739,10 @@ private void overlay(Properties to, Properties from) {
|
|||||||
private void loadProperty(Properties properties, String name, String attr,
|
private void loadProperty(Properties properties, String name, String attr,
|
||||||
String value, boolean finalParameter, String[] source) {
|
String value, boolean finalParameter, String[] source) {
|
||||||
if (value != null || allowNullValueProperties) {
|
if (value != null || allowNullValueProperties) {
|
||||||
if (!finalParameters.contains(attr)) {
|
if (value == null) {
|
||||||
if (value==null && allowNullValueProperties) {
|
|
||||||
value = DEFAULT_STRING_CHECK;
|
value = DEFAULT_STRING_CHECK;
|
||||||
}
|
}
|
||||||
|
if (!finalParameters.contains(attr)) {
|
||||||
properties.setProperty(attr, value);
|
properties.setProperty(attr, value);
|
||||||
if(source != null) {
|
if(source != null) {
|
||||||
updatingResource.put(attr, source);
|
updatingResource.put(attr, source);
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.hadoop.conf.Configuration.IntegerRanges;
|
import org.apache.hadoop.conf.Configuration.IntegerRanges;
|
||||||
@ -49,6 +50,7 @@
|
|||||||
import org.apache.hadoop.io.IOUtils;
|
import org.apache.hadoop.io.IOUtils;
|
||||||
import org.apache.hadoop.net.NetUtils;
|
import org.apache.hadoop.net.NetUtils;
|
||||||
import static org.apache.hadoop.util.PlatformName.IBM_JAVA;
|
import static org.apache.hadoop.util.PlatformName.IBM_JAVA;
|
||||||
|
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
@ -1511,6 +1513,19 @@ public void run() {
|
|||||||
// it's expected behaviour.
|
// 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 {
|
public static void main(String[] argv) throws Exception {
|
||||||
junit.textui.TestRunner.main(new String[]{
|
junit.textui.TestRunner.main(new String[]{
|
||||||
TestConfiguration.class.getName()
|
TestConfiguration.class.getName()
|
||||||
|
Loading…
Reference in New Issue
Block a user