Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3747567B9 for ; Thu, 4 Aug 2011 20:27:50 +0000 (UTC) Received: (qmail 10377 invoked by uid 500); 4 Aug 2011 20:27:49 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 10321 invoked by uid 500); 4 Aug 2011 20:27:49 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 10313 invoked by uid 99); 4 Aug 2011 20:27:49 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Aug 2011 20:27:49 +0000 X-ASF-Spam-Status: No, hits=-2000.7 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Aug 2011 20:27:47 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 25CB2A8B3D for ; Thu, 4 Aug 2011 20:27:27 +0000 (UTC) Date: Thu, 4 Aug 2011 20:27:27 +0000 (UTC) From: "Oliver Heger (JIRA)" To: issues@commons.apache.org Message-ID: <1343931495.9194.1312489647151.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <365727159.24431.1301582885942.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Resolved] (CONFIGURATION-442) SubsetConfiguration does not properly list attributes when a delimiter is set MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CONFIGURATION-442?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Oliver Heger resolved CONFIGURATION-442. ---------------------------------------- Resolution: Won't Fix Fix Version/s: 1.7 There is a workaround for this problem. > SubsetConfiguration does not properly list attributes when a delimiter is set > ----------------------------------------------------------------------------- > > Key: CONFIGURATION-442 > URL: https://issues.apache.org/jira/browse/CONFIGURATION-442 > Project: Commons Configuration > Issue Type: Bug > Affects Versions: 1.6 > Environment: all > Reporter: Fabien Nisol > Fix For: 1.7 > > > imagine a XmlConfiguration like this: > {code} > > > > attr1="attr1" > attr2="attr2"/> > > > > {code} > If subset get instanciated to the end of the hierarchy, with a specific delimiter, getKeys() won't return the correct keys: > {code} > ... > XMLConfiguration config = new XMLConfiguration("test/test.xml"); > Configuration subset = new SubsetConfiguration(config,"prop1.prop2.prop","."); > ConfigurationUtils.dump(subset, System.err); > ... > {code} > gives the result: > {code} > @attr1]=null > @attr2]=null > {code} > it should give the result > {code} > [@attr1]=attr1 > [@attr2]=attr2 > {code} > The wrong dump is a side effect of the wrong implementation of the _getChildKey_ method of SubsetConfiguration > {code} > /** > * Return the key in the subset configuration associated to the specified > * key in the parent configuration. > * > * @param key The key in the parent configuration. > * @return the key in the context of this subset configuration > */ > protected String getChildKey(String key) > { > if (!key.startsWith(prefix)) > { > throw new IllegalArgumentException("The parent key '" + key + "' is not in the subset."); > } > else > { > String modifiedKey = null; > if (key.length() == prefix.length()) > { > modifiedKey = ""; > } > else > { > int i = prefix.length() + (delimiter != null ? delimiter.length() : 0); > modifiedKey = key.substring(i); > } > return modifiedKey; > } > } > {code} > In this code, the _else_ part is wrong. In a hierarchical configuration, the attribute delimiter is '[' and is removed here. > I think a more correct code would be : > {code} > /** > * Return the key in the subset configuration associated to the specified > * key in the parent configuration. > * > * @param key The key in the parent configuration. > * @return the key in the context of this subset configuration > */ > protected String getChildKey(String key) > { > if (!key.startsWith(prefix)) > { > throw new IllegalArgumentException("The parent key '" + key + "' is not in the subset."); > } > else > { > String modifiedKey = null; > if (key.length() == prefix.length()) > { > modifiedKey = ""; > } > else > { > modifiedKey = key.substring(prefix.length()); > if(delimiter!=null && modifiedKey.startsWith(delimiter)) > { > modifiedKey=modifiedKey.substring(delimiter.length()); > } > } > return modifiedKey; > } > } > {code} -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira