[
https://issues.apache.org/jira/browse/CONFIGURATION-837?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17784972#comment-17784972
]
Rob Walker commented on CONFIGURATION-837:
------------------------------------------
Not proposing the attached as a proper / long term solution, but I think it
does prove the issue and solve it by creating a cloneable subclass.
[^MapConfiguration.java]
And yes, I know it's not using generics properly. I wanted to make sure I was
understanding the issue properly.
> 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)