Author: oheger Date: Sun Mar 11 21:00:43 2018 New Revision: 1826461 URL: http://svn.apache.org/viewvc?rev=1826461&view=rev Log: CONFIGURATION-688: Fixed bug related to multiple include files.
The locator pointing to the current configuration file was changed when an include file was loaded. This could cause another include file to fail. The locator is now saved and restored after an include file has been processed. Added: commons/proper/configuration/trunk/src/test/resources/config/testMultiInclude.properties Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java?rev=1826461&r1=1826460&r2=1826461&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java (original) +++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java Sun Mar 11 21:00:43 2018 @@ -1446,7 +1446,15 @@ public class PropertiesConfiguration ext FileHandler fh = new FileHandler(this); fh.setFileLocator(locator); - fh.load(url); + FileLocator orgLocator = locator; + try + { + fh.load(url); + } + finally + { + locator = orgLocator; // reset locator which is changed by load + } } /** Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java?rev=1826461&r1=1826460&r2=1826461&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java (original) +++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java Sun Mar 11 21:00:43 2018 @@ -233,6 +233,23 @@ public class TestPropertiesConfiguration assertEquals("Data not loaded", PROP_VALUE, conf.getString(PROP_NAME)); } + /** + * Tests whether multiple include files can be resolved. + */ + @Test + public void testMultipleIncludeFiles() throws ConfigurationException + { + conf = new PropertiesConfiguration(); + FileHandler handler = new FileHandler(conf); + handler.load(ConfigurationAssert.getTestFile("config/testMultiInclude.properties")); + assertEquals("Wrong top-level property", "topValue", + conf.getString("top")); + assertEquals("Wrong included property (1)", 100, + conf.getInt("property.c")); + assertEquals("Wrong included property (2)", true, + conf.getBoolean("include.loaded")); + } + @Test public void testSetInclude() throws Exception { Added: commons/proper/configuration/trunk/src/test/resources/config/testMultiInclude.properties URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/resources/config/testMultiInclude.properties?rev=1826461&view=auto ============================================================================== --- commons/proper/configuration/trunk/src/test/resources/config/testMultiInclude.properties (added) +++ commons/proper/configuration/trunk/src/test/resources/config/testMultiInclude.properties Sun Mar 11 21:00:43 2018 @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +top = topValue +include = ../include.properties +include = ../testEqual.properties