This is an automated email from the ASF dual-hosted git repository.
dmvolod pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 8041712 CAMEL-12601: DefaultFactoryRegistry.unregister throws
ConcurrentModificationException
8041712 is described below
commit 8041712fbbcf3d5a411023260eb536363b5ec597
Author: Dmitry Volodin <[email protected]>
AuthorDate: Wed Jun 27 22:59:18 2018 +0300
CAMEL-12601: DefaultFactoryRegistry.unregister throws
ConcurrentModificationException
---
.../format/factories/DefaultFactoryRegistry.java | 4 +--
.../factories/DefaultFactoryRegistryTest.java | 36 ++++++++++++++++++++++
2 files changed, 37 insertions(+), 3 deletions(-)
diff --git
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DefaultFactoryRegistry.java
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DefaultFactoryRegistry.java
index 9b52b6a..6f4d044 100644
---
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DefaultFactoryRegistry.java
+++
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DefaultFactoryRegistry.java
@@ -101,9 +101,7 @@ public final class DefaultFactoryRegistry implements
FactoryRegistry {
@Override
public FactoryRegistry unregister(Class<? extends FormatFactoryInterface>
clazz) {
for (Map.Entry<Class<?>, List<FormatFactoryInterface>> entry :
classBasedFactories.entrySet()) {
- entry.getValue().stream().filter(factory -> factory.getClass() ==
clazz).forEach(factory -> {
- entry.getValue().remove(factory);
- });
+ entry.getValue().removeIf(factory -> factory.getClass() == clazz);
}
return this;
}
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/format/factories/DefaultFactoryRegistryTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/format/factories/DefaultFactoryRegistryTest.java
new file mode 100644
index 0000000..3d84993
--- /dev/null
+++
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/format/factories/DefaultFactoryRegistryTest.java
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dataformat.bindy.format.factories;
+
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+
+public class DefaultFactoryRegistryTest {
+
+ @Test(expected = IllegalArgumentException.class)
+ public void unregisterFormatFactory() {
+ FactoryRegistry reg = new DefaultFactoryRegistry();
+ FormattingOptions formattingOptions = new
FormattingOptions().forClazz(String.class);
+
+ assertNotNull(reg.findForFormattingOptions(formattingOptions));
+
+ reg.unregister(StringFormatFactory.class);
+ reg.findForFormattingOptions(formattingOptions);
+ }
+}
\ No newline at end of file