Uploaded image for project: 'Commons Configuration'
  1. Commons Configuration
  2. CONFIGURATION-618

Accessing missing properties of immutable subset throws UndeclaredThrowableException instead of NoSuchElementException

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta2
    • Fix Version/s: 2.0
    • Component/s: None
    • Labels:
      None
    • Environment:

      Oracle JDK 1.8.0_60

      Description

      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:

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

      gives the stacktrace:

      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
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              roshh Robert Schimansky
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: