From 5453e0283ea871ac269104808d4fbb9d0e6a47ae Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 29 Dec 2023 08:53:23 +0100 Subject: [PATCH] Use constructor injection in aaa-password-service Clean up OSGiPasswordServiceConfigBootstrap to not leak its implementation details into the service registry and use constructor injection to keep upgraded SpotBugs happy. Change-Id: I15ff8bc4b4af6305bc30a95b71402919501d7164 Signed-off-by: Robert Varga --- .../OSGiPasswordServiceConfigBootstrap.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/aaa-password-service/impl/src/main/java/org/opendaylight/aaa/impl/password/service/OSGiPasswordServiceConfigBootstrap.java b/aaa-password-service/impl/src/main/java/org/opendaylight/aaa/impl/password/service/OSGiPasswordServiceConfigBootstrap.java index e98caab2e..3c6183765 100644 --- a/aaa-password-service/impl/src/main/java/org/opendaylight/aaa/impl/password/service/OSGiPasswordServiceConfigBootstrap.java +++ b/aaa-password-service/impl/src/main/java/org/opendaylight/aaa/impl/password/service/OSGiPasswordServiceConfigBootstrap.java @@ -7,6 +7,8 @@ */ package org.opendaylight.aaa.impl.password.service; +import static java.util.Objects.requireNonNull; + import com.google.common.annotations.Beta; import com.google.common.collect.Iterables; import java.util.Collection; @@ -30,22 +32,20 @@ import org.slf4j.LoggerFactory; @Beta -@Component(immediate = true) +@Component(service = { }) public final class OSGiPasswordServiceConfigBootstrap implements ClusteredDataTreeChangeListener { private static final Logger LOG = LoggerFactory.getLogger(OSGiPasswordServiceConfigBootstrap.class); - @Reference - DataBroker dataBroker = null; - - @Reference(target = "(component.factory=" + OSGiPasswordServiceConfig.FACTORY_NAME + ")") - ComponentFactory configFactory = null; - + private final ComponentFactory configFactory; private ListenerRegistration registration; private ComponentInstance instance; @Activate - synchronized void activate() { + public OSGiPasswordServiceConfigBootstrap(@Reference final DataBroker dataBroker, + @Reference(target = "(component.factory=" + OSGiPasswordServiceConfig.FACTORY_NAME + ")") + final ComponentFactory configFactory) { + this.configFactory = requireNonNull(configFactory); registration = dataBroker.registerDataTreeChangeListener( DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(PasswordServiceConfig.class)), this); @@ -77,7 +77,7 @@ public synchronized void onDataTreeChanged(final Collection newInstance = configFactory.newInstance( + final var newInstance = configFactory.newInstance( OSGiPasswordServiceConfig.props(config != null ? config : new PasswordServiceConfigBuilder().build())); if (instance != null) { instance.dispose();