[ 
https://issues.apache.org/jira/browse/CONFIGURATION-618?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Oliver Heger resolved CONFIGURATION-618.
----------------------------------------
       Resolution: Fixed
    Fix Version/s: 2.0

Fixed in svn in revision 1728999.

Many thanks for the report!

> Accessing missing properties of immutable subset throws 
> UndeclaredThrowableException instead of NoSuchElementException
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-618
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-618
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 2.0-beta2
>         Environment: Oracle JDK 1.8.0_60
>            Reporter: Robert Schimansky
>            Priority: Minor
>             Fix For: 2.0
>
>
> When I access a non-existing property of a configuration that has 
> ThrowExceptionOnMissing set an java.lang.reflect.UndeclaredThrowableException 
> is thrown. I think the desired behaviour would be to pass the underlying 
> java.util.NoSuchElementException through from the 
> ImmutableConfigurationInvocationHandler.
> Example code:
> {code}
> import org.apache.commons.configuration2.ImmutableConfiguration;
> import org.apache.commons.configuration2.PropertiesConfiguration;
> public class ImmutableConfigurationStacktraceTest {
>       public static void main(String[] args) {
>               //create empty PropertiesConfiguration
>               PropertiesConfiguration propertiesConfiguration = new 
> PropertiesConfiguration();
>               //throw error when non-existing property is requested
>               propertiesConfiguration.setThrowExceptionOnMissing(true);
>               
>               //get immutable subset handled by 
> ImmutableConfigurationInvocationHandler
>               ImmutableConfiguration subset = 
> propertiesConfiguration.immutableSubset("");
>               
>               //this should throw java.util.NoSuchElementException
>               subset.getString("whoops!");
>       }
> }
> {code}
> gives the stacktrace:
> {code}
> Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
>       at com.sun.proxy.$Proxy0.getString(Unknown Source)
>       at test.main(test.java:10)
> Caused by: java.lang.reflect.InvocationTargetException
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>       at java.lang.reflect.Method.invoke(Method.java:497)
>       at 
> org.apache.commons.configuration2.ImmutableConfigurationInvocationHandler.invoke(ImmutableConfigurationInvocationHandler.java:79)
>       ... 2 more
> Caused by: java.util.NoSuchElementException: Key 'whoops!' does not map to an 
> existing object!
>       at 
> org.apache.commons.configuration2.AbstractConfiguration.throwMissingPropertyException(AbstractConfiguration.java:1873)
>       at 
> org.apache.commons.configuration2.AbstractConfiguration.convert(AbstractConfiguration.java:1784)
>       at 
> org.apache.commons.configuration2.AbstractConfiguration.getString(AbstractConfiguration.java:1343)
>       ... 7 more
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to