Fix incorrect statement ordering in augment 34/87634/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 12 Feb 2020 16:22:41 +0000 (17:22 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 12 Feb 2020 17:25:28 +0000 (18:25 +0100)
This is a day-0 bug pointed out by SpotBugs: the increment here is
ineffective, as the Integer is unboxed, incremented and the result
is thrown away -- leading to a dead store and incorrect operation.

Fix this by separating the variables, making it clear what is going
on.

Change-Id: I1393fcdf0e95394fd5a18cf8d843ce2f9e07f898
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/augment/AbstractAugmentStatementSupport.java

index 87b690388d5499de6e035c60fd3c531760f86c43..4bb11bb9c3fa927a1fac2e141c450310d5b8661b 100644 (file)
@@ -129,14 +129,9 @@ abstract class AbstractAugmentStatementSupport
             }
 
             private void updateAugmentOrder(final StatementContextBase<?, ?, ?> augmentSourceCtx) {
-                Integer currentOrder = augmentSourceCtx.getFromNamespace(StmtOrderingNamespace.class,
+                final Integer prev = augmentSourceCtx.getFromNamespace(StmtOrderingNamespace.class,
                     YangStmtMapping.AUGMENT);
-                if (currentOrder == null) {
-                    currentOrder = 1;
-                } else {
-                    currentOrder++;
-                }
-
+                final int currentOrder = prev == null ? 1 : prev + 1;
                 augmentSourceCtx.addToNs(StmtOrderingNamespace.class, YangStmtMapping.AUGMENT, currentOrder);
             }