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

Rob Walker commented on CONFIGURATION-837:
------------------------------------------

Thanks Gary - I did think that was likely to be the case. Not viable for us to 
migrate at this time, but we can fix it in our own local fork.

FWIW (and for anyone else who lands here) - another option here seems to be 
just to use the 2.x flavour of convertPropertiesToMap:
{code:java}
    /**
     * Helper method for converting the type of the {@code Properties} object 
to a supported map type. As stated by the
     * comment of the constructor, we expect the {@code Properties} object to 
contain only String key; therefore, it is safe
     * to do this cast.
     *
     * @param props the {@code Properties} to be copied
     * @return a newly created map with all string keys of the properties
     */
    @SuppressWarnings("unchecked")
    private static Map<String, Object> convertPropertiesToMap(final Properties 
props) {
        @SuppressWarnings("rawtypes")
        final Map map = props;
        return map;
    }  {code}

> MapConfiguration$1 does not implement Cloneable exception
> ---------------------------------------------------------
>
>                 Key: CONFIGURATION-837
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-837
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.10
>            Reporter: Rob Walker
>            Priority: Major
>         Attachments: MapConfiguration.java
>
>
> Note sure if 1.10 is actively maintained, but there's an issue with cloning 
> MapConfiguration objects.
> When trying to convert using an interpolatedConfiguration:
>  
> {code:java}
> Map expanded = 
> ConfigurationConverter.getProperties(launchConfig.interpolatedConfiguration());
>  
> {code}
> The following exception is thrown
>  
> {code:java}
> org.apache.commons.configuration.ConfigurationRuntimeException: 
> java.lang.reflect.InvocationTargetException at 
> org.apache.commons.configuration.ConfigurationUtils.clone(ConfigurationUtils.java:325)
>  at 
> org.apache.commons.configuration.ConfigurationUtils.cloneConfiguration(ConfigurationUtils.java:282)
>  at 
> org.apache.commons.configuration.CombinedConfiguration.clone(CombinedConfiguration.java:670)
>  at 
> org.apache.commons.configuration.HierarchicalConfiguration.interpolatedConfiguration(HierarchicalConfiguration.java:937)
>  at com.ascert.vt.launch.VtLauncher.launchFelix(VtLauncher.java:1220)  Caused 
> by: java.lang.reflect.InvocationTargetException at 
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native 
> Method) at 
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>  at 
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  at java.base/java.lang.reflect.Method.invoke(Method.java:566) at 
> org.apache.commons.configuration.ConfigurationUtils.clone(ConfigurationUtils.java:311)
>  ... 7 more Caused by: 
> org.apache.commons.configuration.ConfigurationRuntimeException: 
> java.lang.CloneNotSupportedException: 
> org.apache.commons.configuration.MapConfiguration$1 does not implement 
> Cloneable at 
> org.apache.commons.configuration.MapConfiguration.clone(MapConfiguration.java:249)
>  ... 12 more Caused by: java.lang.CloneNotSupportedException: 
> org.apache.commons.configuration.MapConfiguration$1 does not implement 
> Cloneable at 
> org.apache.commons.configuration.ConfigurationUtils.clone(ConfigurationUtils.java:330)
>  at 
> org.apache.commons.configuration.MapConfiguration.clone(MapConfiguration.java:242)
>  ... 12 more
>  
> {code}
> The issue seems to be caused by extending AbstractMap as an anyonymous return 
> class. From line 253 of MapConfiguration:
>  
> {code:java}
>     /**
>      * Helper method for copying all string keys from the given
>      * {@code Properties} object to a newly created map.
>      *
>      * @param props the {@code Properties} to be copied
>      * @return a newly created map with all string keys of the properties
>      */
>     private static Map<String, Object> convertPropertiesToMap(final 
> Properties props)
>     {
>         return new AbstractMap<String, Object>() {            
>             @Override
>             public Set<Map.Entry<String, Object>> entrySet()
>  
> {code}
> This class does not implement Cloneable as noted in the error message.
> Don't really know the rest of the code well enough to know whether it could 
> just return a cloneable subclass here (such as HashMap) or if that's not the 
> best way to go as that then becomes a mutable Map which AbstractMap is not. I 
> guess another approach would be to create an inner class based on this which 
> supports Cloneable and implements a manual clone() method, but nothing else.
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to