From: Robert Varga Date: Tue, 30 Aug 2016 16:41:48 +0000 (+0200) Subject: BUG-6497: Do not lose augmentation statement order X-Git-Tag: release/beryllium-sr4~7 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=yangtools.git;a=commitdiff_plain;h=6d051fb473374c133474d2e90aa68663ae948763 BUG-6497: Do not lose augmentation statement order Using an interim HashSet can cause unpredictable order of augmentations, which means the binding spec will not assign consistent mapping at runtime. Fix this by using a LinkedHashSet, which retains insertion order. Change-Id: I503102d8b61453cc9c8d35b07158cd97138cda42 Signed-off-by: Robert Varga (cherry picked from commit 3c4bdfac3a8b04ecd1d6eab2cdadbb365b54664e) --- diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveSimpleDataNodeContainer.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveSimpleDataNodeContainer.java index 43ff80b259..e343df4011 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveSimpleDataNodeContainer.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveSimpleDataNodeContainer.java @@ -10,7 +10,7 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import java.util.ArrayList; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import org.opendaylight.yangtools.yang.common.QName; @@ -51,7 +51,7 @@ abstract class AbstractEffectiveSimpleDataNodeContainer unknownNodesInit = new ArrayList<>(); - Set augmentationsInit = new HashSet<>(); + Set augmentationsInit = new LinkedHashSet<>(); for (EffectiveStatement effectiveStatement : effectiveSubstatements()) { if (effectiveStatement instanceof UnknownSchemaNode) { unknownNodesInit.add((UnknownSchemaNode) effectiveStatement); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ChoiceEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ChoiceEffectiveStatementImpl.java index f7e9966cec..5af6a441a4 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ChoiceEffectiveStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ChoiceEffectiveStatementImpl.java @@ -11,7 +11,7 @@ import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import java.util.Collection; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Objects; import java.util.Set; import java.util.SortedSet; @@ -51,7 +51,7 @@ public final class ChoiceEffectiveStatementImpl extends AbstractEffectiveDataSch // initSubstatementCollectionsAndFields Collection> effectiveSubstatements = effectiveSubstatements(); - Set augmentationsInit = new HashSet<>(); + Set augmentationsInit = new LinkedHashSet<>(); SortedSet casesInit = new TreeSet<>(Comparators.SCHEMA_NODE_COMP); for (EffectiveStatement effectiveStatement : effectiveSubstatements) { diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/NotificationEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/NotificationEffectiveStatementImpl.java index 67e46139c8..d92eeb4228 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/NotificationEffectiveStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/NotificationEffectiveStatementImpl.java @@ -10,7 +10,7 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import java.util.Collection; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Objects; @@ -40,7 +40,7 @@ public class NotificationEffectiveStatementImpl extends // initSubstatementCollections Collection> effectiveSubstatements = effectiveSubstatements(); List unknownNodesInit = new LinkedList<>(); - Set augmentationsInit = new HashSet<>(); + Set augmentationsInit = new LinkedHashSet<>(); for (EffectiveStatement effectiveStatement : effectiveSubstatements) { if (effectiveStatement instanceof UnknownSchemaNode) { UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;