You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Rob Walker (JIRA)" <ji...@apache.org> on 2010/01/14 14:52:54 UTC

[jira] Commented: (CONFIGURATION-336) Brackets in property key causes NumberFormatException

    [ https://issues.apache.org/jira/browse/CONFIGURATION-336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12800203#action_12800203 ] 

Rob Walker commented on CONFIGURATION-336:
------------------------------------------

The fixes above provide a workaround, but it's not exactly a "low pain / low effort" option, and is made harder by a lot of use of private methods in DefaultConfigurationKey etc preventing a simple subclassing approach.

I suspect it's going to become a bigger issue for more people too, since Vista and Windows 7 both have additional environment/path variables that break this e.g.

ProgamFiles(x86) 

It seems a small and simple fix to DefaultConfigurationKey.KeyIterator could take away a ton of pain for the simple case e.g.

        private boolean checkIndex(String key)
        {
            boolean result = false;

            try
            {
                int idx = key.lastIndexOf(getExpressionEngine().getIndexStart());
                if (idx > 0)
                {
                    int endidx = key.indexOf(getExpressionEngine().getIndexEnd(),
                            idx);
    
                    if (endidx > idx + 1)
                    {
                        indexValue = Integer.parseInt(key.substring(idx + 1, endidx));
                        current = key.substring(0, idx);
                        result = true;
                    }
                }
            }
            catch (NumberFormatException nfe)
            {
                result = false;
            }

            return result;
        }


> Brackets in property key causes NumberFormatException
> -----------------------------------------------------
>
>                 Key: CONFIGURATION-336
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-336
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.5
>            Reporter: Pavel Savara
>            Assignee: Oliver Heger
>             Fix For: 1.6
>
>
> Hi,
> When using brackets in property key we get an exception every time.
> Escaping brackets with \ doesn't help.
> Example
> #property in property file
> test(ef)=false
> causes 
> java.lang.NumberFormatException: For input string: "ef" at
> java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
>         at java.lang.Integer.parseInt(Integer.java:447)
>         at java.lang.Integer.parseInt(Integer.java:497)
>         at org.apache.commons.configuration.tree.DefaultConfigurationKey
> $KeyIterator.checkIndex(DefaultConfigurationKey.java:834)
>         at org.apache.commons.configuration.tree.DefaultConfigurationKey
> $KeyIterator.nextKey(DefaultConfigurationKey.java:511) at
> org.apache.commons.configuration.tree.DefaultExpressionEngine.findNodesForKey(DefaultExpressionEngine.java:462) at
> org.apache.commons.configuration.tree.DefaultExpressionEngine.query(DefaultExpressionEngine.java:286) at
> org.apache.commons.configuration.HierarchicalConfiguration.fetchNodeList(HierarchicalConfiguration.java:925 at
> org.apache.commons.configuration.HierarchicalConfiguration.setProperty(HierarchicalConfiguration.java:735) at
> org.apache.commons.configuration.ConfigurationUtils.copy(ConfigurationUtils.java:143) at
> org.apache.commons.configuration.ConfigurationUtils.convertToHierarchical(ConfigurationUtils.java:199)  at org.apache.commons.configuration.CombinedConfiguration
> $ConfigData.getTransformedRoot(CombinedConfiguration.java:794)  at
> org.apache.commons.configuration.CombinedConfiguration.constructCombinedNode(CombinedConfiguration.java:653) at
> org.apache.commons.configuration.CombinedConfiguration.getRootNode(CombinedConfiguration.java:504) at
> org.apache.commons.configuration.HierarchicalConfiguration.fetchNodeList(HierarchicalConfiguration.java:925) at
> org.apache.commons.configuration.HierarchicalConfiguration.getProperty(HierarchicalConfiguration.java:327) at
> org.apache.commons.configuration.CombinedConfiguration.getProperty(CombinedConfiguration.java:578) at
> org.apache.commons.configuration.AbstractConfiguration.resolveContainerStore(AbstractConfiguration.java:1155) at
> org.apache.commons.configuration.AbstractConfiguration.getString(AbstractConfiguration.java:1034)  at
> org.apache.commons.configuration.AbstractConfiguration.getString(AbstractConfiguration.java:1017) 
> Explanation i got in mailing list from Oliver Heger
> I guess you use DefaultConfigurationBuilder for loading a combined 
> configuration?
> The exception is due to the fact that brackets have a special meaning in 
> the query syntax for hierarchical configurations. 
> (DefaultConfigurationBuilder transforms all configuration sources into 
> hierarchical configurations, so also for properties, which are not 
> hierarchical by default, the same rules apply.)
> So far escaping brackets or other specific characters in property keys 
> is not supported. It seems to be rather unusual to use brackets in 
> property keys, so you may well be the first one who noticed this problem.
> Unfortunately I don't have a working solution for this problem right 
> now.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.