From 11c7b246e0e351edbfc5f2457a0f59082d85f552 Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 18 Aug 2016 09:35:58 +1000 Subject: [PATCH] #1938: Better handling of null config keys --- .../net/md_5/bungee/config/Configuration.java | 2 +- .../bungee/config/YamlConfigurationTest.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/config/src/main/java/net/md_5/bungee/config/Configuration.java b/config/src/main/java/net/md_5/bungee/config/Configuration.java index 9f3464d9..a7ddf3a3 100644 --- a/config/src/main/java/net/md_5/bungee/config/Configuration.java +++ b/config/src/main/java/net/md_5/bungee/config/Configuration.java @@ -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 ) { diff --git a/config/src/test/java/net/md_5/bungee/config/YamlConfigurationTest.java b/config/src/test/java/net/md_5/bungee/config/YamlConfigurationTest.java index df135b0f..c400b92f 100644 --- a/config/src/test/java/net/md_5/bungee/config/YamlConfigurationTest.java +++ b/config/src/test/java/net/md_5/bungee/config/YamlConfigurationTest.java @@ -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" ) ); + } }