BUG-2401: remove LOG.warn() from entrySet() 24/12924/1
authorRobert Varga <rovarga@cisco.com>
Tue, 18 Nov 2014 17:37:32 +0000 (18:37 +0100)
committerRobert Varga <rovarga@cisco.com>
Tue, 18 Nov 2014 17:37:32 +0000 (18:37 +0100)
As it turns out, entrySet() is called from
AbstractImmutableDataContainerNodeBuilder when it modifies children (via
HashMap(Map) contructor). Remove the warning and add explanation about
what is going on.

Change-Id: Ifbd99458c83d8afa25c3be7778fb28b579d4b2d8
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/UnmodifiableChildrenMap.java

index 49887cc329eece51ab471bd213936e1ec9dca70a..98598aa31e8d852b1dc284bd889dcc73375aaac6 100644 (file)
@@ -16,15 +16,12 @@ import java.util.Map;
 import java.util.Set;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Internal equivalent of {@link Collections}' unmodifiable Map. It does not retain
  * keySet/entrySet references, thus lowering the memory overhead.
  */
 final class UnmodifiableChildrenMap implements Map<PathArgument, DataContainerChild<? extends PathArgument, ?>>, Serializable {
-    private static final Logger LOG = LoggerFactory.getLogger(UnmodifiableChildrenMap.class);
     private static final long serialVersionUID = 1L;
     private final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> delegate;
     private transient Collection<DataContainerChild<? extends PathArgument, ?>> values;
@@ -115,11 +112,16 @@ final class UnmodifiableChildrenMap implements Map<PathArgument, DataContainerCh
 
     @Override
     public Set<Entry<PathArgument, DataContainerChild<? extends PathArgument, ?>>> entrySet() {
-        LOG.warn("Invocation of inefficient entrySet()", new Throwable().fillInStackTrace());
+        /*
+         * Okay, this is not as efficient as it could be -- we could save ourselves the
+         * map instantiation. The cost of that would be re-implementation of a read-only
+         * Map.Entry to ensure our delegate is never modified.
+         *
+         * Let's skip that and use whatever the JRE gives us instead.
+         */
         return Collections.unmodifiableMap(delegate).entrySet();
     }
 
-
     @Override
     public boolean equals(final Object o) {
         return this == o || delegate.equals(o);