From 6b7046c8b710ec65100f20c9ee36d2c0a99f75f2 Mon Sep 17 00:00:00 2001 From: Minoneer Date: Sun, 7 Jan 2018 23:19:17 +0100 Subject: [PATCH] Fixes lookup of default configuration values for nested paths (#2322) The lookup of default configuration values with multiple path segments failed with a class cast exception because the full path was treated as a new configuration section instead of only the root. --- .../net/md_5/bungee/config/Configuration.java | 2 +- .../config/DefaultConfigurationTest.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 config/src/test/java/net/md_5/bungee/config/DefaultConfigurationTest.java 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 967a1b2a..2ffc80bc 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 @@ -56,7 +56,7 @@ public final class Configuration Object section = self.get( root ); if ( section == null ) { - section = new Configuration( ( defaults == null ) ? null : defaults.getSection( path ) ); + section = new Configuration( ( defaults == null ) ? null : defaults.getSection( root ) ); self.put( root, section ); } diff --git a/config/src/test/java/net/md_5/bungee/config/DefaultConfigurationTest.java b/config/src/test/java/net/md_5/bungee/config/DefaultConfigurationTest.java new file mode 100644 index 00000000..a9a5b9df --- /dev/null +++ b/config/src/test/java/net/md_5/bungee/config/DefaultConfigurationTest.java @@ -0,0 +1,22 @@ +package net.md_5.bungee.config; + +import org.junit.Assert; +import org.junit.Test; + +public class DefaultConfigurationTest +{ + @Test + public void testDefaultValues() + { + Configuration defaultConfig = new Configuration(); + defaultConfig.set( "setting", 10 ); + defaultConfig.set( "nested.setting", 11 ); + defaultConfig.set( "double.nested.setting", 12 ); + + Configuration actualConfig = new Configuration( defaultConfig ); + + Assert.assertEquals( 10, actualConfig.getInt( "setting" ) ); + Assert.assertEquals( 11, actualConfig.getInt( "nested.setting" ) ); + Assert.assertEquals( 12, actualConfig.getInt( "double.nested.setting" ) ); + } +}