#1938: Better handling of null config keys

This commit is contained in:
md_5 2016-08-18 09:35:58 +10:00
parent 37b3cb4a30
commit 11c7b246e0
2 changed files with 17 additions and 1 deletions

View File

@ -32,7 +32,7 @@ public final class Configuration
for ( Map.Entry<?, ?> entry : map.entrySet() )
{
String key = entry.getKey().toString();
String key = ( entry.getKey() == null ) ? "null" : entry.getKey().toString();
if ( entry.getValue() instanceof Map )
{

View File

@ -49,6 +49,10 @@ public class YamlConfigurationTest
+ " 2: 2\n"
+ " 3: 3\n"
+ " 4: 4";
private static final String NULL_TEST = ""
+ "null:\n"
+ " null: object\n"
+ " object: null\n";
@Test
public void testConfig() throws Exception
@ -103,4 +107,16 @@ public class YamlConfigurationTest
// empty
}
}
@Test
public void testNull()
{
Configuration conf = ConfigurationProvider.getProvider( YamlConfiguration.class ).load( NULL_TEST );
Assert.assertEquals( "object", conf.get( "null.null" ) );
Assert.assertEquals( "object", conf.getSection( "null" ).get( "null" ) );
Assert.assertEquals( null, conf.get( "null.object" ) );
Assert.assertEquals( "", conf.getString( "null.object" ) );
}
}