[
https://issues.apache.org/jira/browse/KARAF-6998?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17301118#comment-17301118
]
Wouter Born commented on KARAF-6998:
------------------------------------
I did some debugging on the continuous configuration updates I ran into. It
seems the [equals check in the
JsonConfigInstaller|https://github.com/apache/karaf/blob/master/config/src/main/java/org/apache/karaf/config/core/impl/JsonConfigInstaller.java#L83]
fails because it calls {{equals}} on an {{OrderDictionary}} which is backed by
a map with {{CaseInsensitiveKey}} keys.
The issue with that is that the hashcode of these keys is [computed using the
string upper case
value|https://github.com/apache/felix-dev/blob/90eee7459c45994b7513c02f995438aa8f6430e8/cm.json/src/main/java/org/apache/felix/cm/json/impl/OrderedDictionary.java#L150].
You can reproduce this issue in a simple unit test:
{code}
@Test
public void comperisonTest() {
Hashtable<String, Object> oldConfig = new Hashtable<>();
oldConfig.put("camelCaseKey", "value");
Hashtable<String, Object> newConfig = Configurations.newConfiguration();
newConfig.put("camelCaseKey", "value");
assertEquals(newConfig, oldConfig);
}
{code}
This test fails, but if you swap the arguments around it succeeds.
So an easy fix in `JsonConfigInstaller` could be to update the comparison to
something like:
{code}
if (old == null || !old.equals(properties)) {
{code}
and add a comment why this is done.
I gave this change a test and it fixes this issue for me. :-)
> Karaf 4.3 Configurations with array property values calls @modified every 2
> seconds
> -----------------------------------------------------------------------------------
>
> Key: KARAF-6998
> URL: https://issues.apache.org/jira/browse/KARAF-6998
> Project: Karaf
> Issue Type: Bug
> Components: karaf
> Affects Versions: 4.3.0
> Reporter: Scott Ortel
> Assignee: Jean-Baptiste Onofré
> Priority: Major
> Fix For: 4.3.1
>
> Attachments: logging.txt
>
>
> Configurations created with configadmin in 4.3 have two issues:
> 1) The configuration is always persisted as JSON by the JsonConfigInstaller
> in 'karaf.etc' and is therefore watched by the file installer. It seems this
> behavior should be governed by the 'felix.cm.dir' setting, which would allow
> these persisted configurations to be placed elsewhere or not at all. This
> differs from the .cfg CM persistence behavior.
> 2) When JsonConfigInstaller examines the configuration and compares it to the
> existing one (setConfig() line 83), by performing a simple .equals() on the
> 'old' and 'properties' hash tables. This does not property handle property
> values that are arrays (valid in OSGi 7). As you know a map simply compares
> the key values using .equals, which for arrays is '=='. This causes the
> configuration to always appear to be modified and the associated component is
> deactivated/activated/modified every 2 seconds.
>
> Thank you for Karaf and for considering this issue.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)