From 3dbcd3ceb1f71626d1e35da01fd3ecbaa7fb58d7 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Fri, 18 Jun 2021 14:47:59 -0400 Subject: Fix new checkstyle issues in drools-pdp The new version of checkstyle identified new issues. Fixed those. Also addressed sonar "var" issues. Issue-ID: POLICY-3289 Change-Id: I3a18d3988202dca6f3c87f2aa1810bf803a9d14d Signed-off-by: Jim Hahn --- .../policy/drools/pooling/EndToEndFeatureTest.java | 4 +-- .../onap/policy/drools/pooling/FeatureTest.java | 5 ++-- .../drools/persistence/PersistenceFeature.java | 33 +++++++++++----------- .../drools/core/lock/AlwaysLockBaseTest.java | 1 + .../policy/drools/system/internal/LockManager.java | 8 +++--- 5 files changed, 25 insertions(+), 26 deletions(-) diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/EndToEndFeatureTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/EndToEndFeatureTest.java index 08c7ebe4..b8970f1f 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/EndToEndFeatureTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/EndToEndFeatureTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -317,7 +317,7 @@ public class EndToEndFeatureTest { /** * Constructor. * - * @param nEvents number of events to be processed + * @param events number of events to be processed */ public Context(int events) { eventCounter = new CountDownLatch(events); diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest.java index efab636b..bbd4c19f 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -231,7 +231,7 @@ public class FeatureTest { /** * Constructor. * - * @param nEvents number of events to be processed + * @param events number of events to be processed */ public Context(int events) { @@ -1002,7 +1002,6 @@ public class FeatureTest { /** * Constructor. * - * @param context this manager's context * @param topic the topic * @throws PoolingFeatureException if an error occurs */ diff --git a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java index efe2a294..3c3e5008 100644 --- a/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java +++ b/feature-session-persistence/src/main/java/org/onap/policy/drools/persistence/PersistenceFeature.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * feature-session-persistence * ================================================================================ - * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ package org.onap.policy.drools.persistence; import java.io.IOException; -import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.HashMap; @@ -152,7 +151,7 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine @Override public PolicySession.ThreadModel selectThreadModel(PolicySession session) { - PolicyContainer policyContainer = session.getPolicyContainer(); + var policyContainer = session.getPolicyContainer(); if (isPersistenceEnabled(policyContainer, session.getName())) { return new PersistentThreadModel(session, getProperties(policyContainer)); } @@ -291,7 +290,7 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine configureSysProps(); BasicDataSource ds = makeDataSource(getDataSourceProperties()); - DsEmf dsemf = new DsEmf(ds); + var dsemf = new DsEmf(ds); try { EntityManagerFactory emf = dsemf.emf; @@ -306,11 +305,11 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine logger.info( "getPolicySession:session does not exist -- attempt to create one with name {}", name); - Environment env = kieSvcFact.newEnvironment(); + var env = kieSvcFact.newEnvironment(); configureKieEnv(env, emf); - KieSessionConfiguration kieConf = kieSvcFact.newKieSessionConfiguration(); + var kieConf = kieSvcFact.newKieSessionConfiguration(); KieSession kieSession = (desiredSessionId >= 0 @@ -343,13 +342,13 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine * @param kieBaseName the name of the 'KieBase' instance containing this session * @param desiredSessionId id of the desired KieSession * @param env Kie Environment for the session - * @param kConf Kie Configuration for the session + * @param kieConf Kie Configuration for the session * @return the persistent session, or {@code null} if it could not be loaded */ private KieSession loadKieSession( String kieBaseName, long desiredSessionId, Environment env, KieSessionConfiguration kieConf) { try { - KieSession kieSession = + var kieSession = kieSvcFact .getStoreServices() .loadKieSession( @@ -376,7 +375,7 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine * @return a new, persistent session */ private KieSession newKieSession(String kieBaseName, Environment env) { - KieSession kieSession = + var kieSession = kieSvcFact .getStoreServices() .newKieSession(policyContainer.getKieContainer().getKieBase(kieBaseName), null, env); @@ -461,7 +460,7 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine */ private void replaceSession(DroolsSessionConnector conn, String sessnm, KieSession kieSession) { - DroolsSessionEntity sess = new DroolsSessionEntity(); + var sess = new DroolsSessionEntity(); sess.setSessionName(sessnm); sess.setSessionId(kieSession.getIdentifier()); @@ -478,7 +477,7 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine * @return the data source properties */ private Properties getDataSourceProperties() { - Properties props = new Properties(); + var props = new Properties(); props.put("driverClassName", persistProps.getProperty(DroolsPersistenceProperties.DB_DRIVER)); props.put("url", persistProps.getProperty(DroolsPersistenceProperties.DB_URL)); props.put("username", persistProps.getProperty(DroolsPersistenceProperties.DB_USER)); @@ -512,7 +511,7 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine // now do the record deletion try (BasicDataSource ds = makeDataSource(getDataSourceProperties()); - Connection connection = ds.getConnection(); + var connection = ds.getConnection(); PreparedStatement statement = connection.prepareStatement( "DELETE FROM sessioninfo WHERE timestampdiff(second,lastmodificationdate,now()) > ?")) { @@ -542,8 +541,8 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine * @return {@code true} if persistence is enabled for this container, and {@code false} if not */ private boolean isPersistenceEnabled(PolicyContainer container, String sessionName) { - Properties properties = getProperties(container); - boolean rval = false; + var properties = getProperties(container); + var rval = false; if (properties != null) { // fetch the 'type' property @@ -635,7 +634,7 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine String name = session.getName(); // fetch 'minSleepTime' value, and update if defined - String sleepTimeString = getProperty(properties, name, "minSleepTime"); + var sleepTimeString = getProperty(properties, name, "minSleepTime"); if (sleepTimeString != null) { try { minSleepTime = Math.max(1, Integer.valueOf(sleepTimeString)); @@ -733,13 +732,13 @@ public class PersistenceFeature implements PolicySessionFeatureApi, PolicyEngine // set thread local variable session.setPolicySession(); - KieSession kieSession = session.getKieSession(); + var kieSession = session.getKieSession(); long sleepTime = 2 * halfMaxSleepTime; // We want to continue, despite any exceptions that occur // while rules are fired. - boolean cont = true; + var cont = true; while (cont) { try { diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/lock/AlwaysLockBaseTest.java b/policy-core/src/test/java/org/onap/policy/drools/core/lock/AlwaysLockBaseTest.java index 1091b260..b5f7a64c 100644 --- a/policy-core/src/test/java/org/onap/policy/drools/core/lock/AlwaysLockBaseTest.java +++ b/policy-core/src/test/java/org/onap/policy/drools/core/lock/AlwaysLockBaseTest.java @@ -40,6 +40,7 @@ public abstract class AlwaysLockBaseTest { protected T lock; @Test + @SuppressWarnings("unchecked") public void testSerializable() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/internal/LockManager.java b/policy-management/src/main/java/org/onap/policy/drools/system/internal/LockManager.java index eee2a50e..88037bbb 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/system/internal/LockManager.java +++ b/policy-management/src/main/java/org/onap/policy/drools/system/internal/LockManager.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -143,14 +143,14 @@ public abstract class LockManager implements PolicyRe boolean waitForLock) { if (hasInstanceChanged()) { - AlwaysFailLock lock = new AlwaysFailLock(resourceId, ownerKey, holdSec, callback); + var lock = new AlwaysFailLock(resourceId, ownerKey, holdSec, callback); lock.notifyUnavailable(); return lock; } T lock = makeLock(LockState.WAITING, resourceId, ownerKey, holdSec, callback); - T existingLock = resource2lock.putIfAbsent(resourceId, lock); + var existingLock = resource2lock.putIfAbsent(resourceId, lock); if (existingLock == null) { logger.debug("added lock to map {}", lock); @@ -192,6 +192,6 @@ public abstract class LockManager implements PolicyRe * lost; must not be {@code null} * @return a new lock */ - protected abstract T makeLock(LockState waiting, String resourceId, String ownerKey, int holdSec, + protected abstract T makeLock(LockState state, String resourceId, String ownerKey, int holdSec, LockCallback callback); } -- cgit 1.2.3-korg