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.
This commit is contained in:
Minoneer 2018-01-07 23:19:17 +01:00 committed by md-5
parent 050d935891
commit 6b7046c8b7
2 changed files with 23 additions and 1 deletions

View File

@ -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 );
}

View File

@ -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" ) );
}
}