Enable spotbugs in yang-parser-rfc7950 81/86581/8
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 26 Dec 2019 13:13:12 +0000 (14:13 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 12 Feb 2020 16:24:37 +0000 (17:24 +0100)
This fixes up the final batch of problems reported by spotbugs
and flips enforcement on so we do not regress.

JIRA: YANGTOOLS-1056
Change-Id: Ib4a56e6ad766039482ca855c6fe4bc565434521d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-rfc7950/pom.xml
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/StmtNamespaceContext.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/augment/AbstractAugmentStatementSupport.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/base/BaseStatementSupport.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/container/AbstractContainerStatementSupport.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/import_/AbstractImportStatementSupport.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/uses/UsesStatementSupport.java

index a9bec0cf25715c688314ad22b5fff288867f1992..2eb82d3495ad3b93f320a67ab68ad8cf7cea911d 100644 (file)
     <name>${project.artifactId}</name>
     <description>RFC6020/RFC7950 parser support</description>
 
-    <properties>
-        <!-- FIXME: YANGTOOLS-1056: remove this knob -->
-        <odlparent.spotbugs.enforce>false</odlparent.spotbugs.enforce>
-    </properties>
-
     <dependencies>
         <dependency>
             <groupId>com.google.guava</groupId>
index ae97fc11d680f754be02acec324ab26df8b8e354..bdff19e551cb6edb536505b9403ad3854a89cbe4 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.yangtools.yang.parser.rfc7950.stmt;
 
 import static java.util.Objects.requireNonNull;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Optional;
 import javax.xml.namespace.NamespaceContext;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -20,11 +21,13 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 /**
  * A {@link NamespaceContext} implementation based on the set of imports and local module namespace.
  */
-// TODO: this is a useful utility, so it may be useful to expose it either in this package, or yang.parser.spi.source.
+// TODO: this is a useful utility, so it may be useful to expose it either in this package, or yang.parser.spi.source,
+//       but that requires dealing with serialization below.
 final class StmtNamespaceContext implements YangNamespaceContext {
-    // FIXME: add serialization barrier
     private static final long serialVersionUID = 1L;
 
+    // FIXME: deal with serialization by serializing the underlying namespace Map
+    @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "Not passed to serialization")
     private final StmtContext<?, ?, ?> ctx;
 
     StmtNamespaceContext(final StmtContext<?, ?, ?> ctx) {
index 4bb11bb9c3fa927a1fac2e141c450310d5b8661b..326a73593c33f9ef959419041459dcbec44bcae7 100644 (file)
@@ -88,14 +88,11 @@ abstract class AbstractAugmentStatementSupport
             return;
         }
 
-        final ModelActionBuilder augmentAction = augmentNode.newInferenceAction(
-            ModelProcessingPhase.EFFECTIVE_MODEL);
-        final Prerequisite<StmtContext<SchemaNodeIdentifier, AugmentStatement,
-                AugmentEffectiveStatement>> sourceCtxPrereq =
-                    augmentAction.requiresCtx(augmentNode, ModelProcessingPhase.EFFECTIVE_MODEL);
-        final Prerequisite<Mutable<?, ?, EffectiveStatement<?, ?>>> target =
-                augmentAction.mutatesEffectiveCtxPath(getSearchRoot(augmentNode),
-                    ChildSchemaNodeNamespace.class, augmentNode.coerceStatementArgument().getPathFromRoot());
+        final ModelActionBuilder augmentAction = augmentNode.newInferenceAction(ModelProcessingPhase.EFFECTIVE_MODEL);
+        augmentAction.requiresCtx(augmentNode, ModelProcessingPhase.EFFECTIVE_MODEL);
+        final Prerequisite<Mutable<?, ?, EffectiveStatement<?, ?>>> target = augmentAction.mutatesEffectiveCtxPath(
+            getSearchRoot(augmentNode), ChildSchemaNodeNamespace.class,
+            augmentNode.coerceStatementArgument().getPathFromRoot());
 
         augmentAction.apply(new InferenceAction() {
             @Override
index 16019ac82b9d8065c1ae7f571bc0c144fe0743d7..93b5acf023886b448a3d32389cf424da28c03e4a 100644 (file)
@@ -62,10 +62,9 @@ public final class BaseStatementSupport extends AbstractQNameStatementSupport<Ba
             final QName baseIdentityQName = baseStmtCtx.coerceStatementArgument();
             final ModelActionBuilder baseIdentityAction = baseStmtCtx.newInferenceAction(
                 ModelProcessingPhase.STATEMENT_DEFINITION);
-            final Prerequisite<StmtContext<?, ?, ?>> requiresPrereq = baseIdentityAction.requiresCtx(baseStmtCtx,
-                IdentityNamespace.class, baseIdentityQName, ModelProcessingPhase.STATEMENT_DEFINITION);
-            final Prerequisite<Mutable<?, ?, ?>> mutatesPrereq = baseIdentityAction.mutatesCtx(baseParentCtx,
+            baseIdentityAction.requiresCtx(baseStmtCtx, IdentityNamespace.class, baseIdentityQName,
                 ModelProcessingPhase.STATEMENT_DEFINITION);
+            baseIdentityAction.mutatesCtx(baseParentCtx, ModelProcessingPhase.STATEMENT_DEFINITION);
 
             baseIdentityAction.apply(new InferenceAction() {
                 @Override
index 79afa2b9b6039e01053c6218e1ba45a6faa46a01..6e63a30e2c783ba74ca47b6bfad7c2689a36db72 100644 (file)
@@ -25,7 +25,6 @@ import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMix
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
 
 abstract class AbstractContainerStatementSupport
         extends BaseQNameStatementSupport<ContainerStatement, ContainerEffectiveStatement> {
@@ -59,7 +58,6 @@ abstract class AbstractContainerStatementSupport
             final StmtContext<QName, ContainerStatement, ContainerEffectiveStatement> ctx,
             final ContainerStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
 
-        final StatementSourceReference ref = ctx.getStatementSourceReference();
         final SchemaPath path = ctx.getSchemaPath().get();
         final ContainerSchemaNode original = (ContainerSchemaNode) ctx.getOriginalCtx().map(StmtContext::buildEffective)
                 .orElse(null);
index bb40970a9ead84d05087db775df616c75135d4fa..2cdd064ab23c140f0deddcbb7fbcf51c2798b7fd 100644 (file)
@@ -60,8 +60,7 @@ abstract class AbstractImportStatementSupport
         final ModelActionBuilder importAction = stmt.newInferenceAction(SOURCE_PRE_LINKAGE);
         final Prerequisite<StmtContext<?, ?, ?>> imported = importAction.requiresCtx(stmt,
                 PreLinkageModuleNamespace.class, moduleName, SOURCE_PRE_LINKAGE);
-        final Prerequisite<Mutable<?, ?, ?>> linkageTarget = importAction
-                .mutatesCtx(stmt.getRoot(), SOURCE_PRE_LINKAGE);
+        importAction.mutatesCtx(stmt.getRoot(), SOURCE_PRE_LINKAGE);
 
         importAction.apply(new InferenceAction() {
             @Override
index b4da726f0d3589756212243faee8a2b05dc4b90b..b11ee1347e4cec9e401d32e792793f73997742a9 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.uses;
 
 import com.google.common.base.Verify;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Optional;
@@ -137,6 +138,8 @@ public final class UsesStatementSupport
      * @throws SourceException
      *             instance of SourceException
      */
+    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
+            justification = "https://github.com/spotbugs/spotbugs/issues/811")
     private static void copyFromSourceToTarget(final Mutable<?, ?, ?> sourceGrpStmtCtx,
             final StatementContextBase<?, ?, ?> targetCtx,
             final Mutable<QName, UsesStatement, UsesEffectiveStatement> usesNode) {
@@ -161,7 +164,6 @@ public final class UsesStatementSupport
         usesNode.addAsEffectOfStatement(buffer);
     }
 
-
     private static boolean shouldCopy(final StmtContext<?, ?, ?> stmt) {
         // https://tools.ietf.org/html/rfc7950#section-7.13:
         //
@@ -216,6 +218,8 @@ public final class UsesStatementSupport
         return null;
     }
 
+    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
+            justification = "https://github.com/spotbugs/spotbugs/issues/811")
     private static void resolveUsesNode(final Mutable<QName, UsesStatement, UsesEffectiveStatement> usesNode,
             final StmtContext<?, ?, ?> targetNodeStmtCtx) {
         for (final Mutable<?, ?, ?> subStmtCtx : usesNode.mutableDeclaredSubstatements()) {