Fix some sonar bugs in config-api and config-manager. 15/5415/2
authorTomas Olvecky <tolvecky@cisco.com>
Wed, 19 Feb 2014 14:43:41 +0000 (15:43 +0100)
committerTomas Olvecky <tolvecky@cisco.com>
Thu, 20 Feb 2014 09:03:44 +0000 (10:03 +0100)
Change-Id: I417bb4bdd649606d871382e7bf561d35daafc11b
Signed-off-by: Tomas Olvecky <tolvecky@cisco.com>
26 files changed:
opendaylight/config/config-api/src/main/java/org/opendaylight/controller/config/api/IdentityAttributeRef.java
opendaylight/config/config-api/src/main/java/org/opendaylight/controller/config/api/JmxAttribute.java
opendaylight/config/config-api/src/main/java/org/opendaylight/controller/config/api/ModuleIdentifier.java
opendaylight/config/config-api/src/main/java/org/opendaylight/controller/config/api/ValidationException.java
opendaylight/config/config-api/src/main/java/org/opendaylight/controller/config/api/jmx/CommitStatus.java
opendaylight/config/config-api/src/main/java/org/opendaylight/controller/config/api/jmx/ObjectNameUtil.java
opendaylight/config/config-api/src/main/java/org/opendaylight/controller/config/api/jmx/constants/ConfigRegistryConstants.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImpl.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerImpl.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ModuleInternalTransactionalInfo.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ServiceReferenceRegistryImpl.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/TransactionIdentifier.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/TransactionStatus.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverImpl.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AbstractDynamicWrapper.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AnnotationsHelper.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AttributeHolder.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/factoriesresolver/HierarchicalConfigMBeanFactoriesHolder.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/InternalJMXRegistrator.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/ServiceReference.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/TransactionJMXRegistrator.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BundleContextBackedModuleFactoriesResolver.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ConfigManagerActivator.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/FtlFilePersister.java
opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleMXBeanEntryBuilder.java
opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/attribute/TOAttribute.java

index 73737593cf6af9359660147a4fb44d145809f6b5..5ad6e0da8d2bf8a29d8d403783e378c5ab950346 100644 (file)
@@ -19,8 +19,9 @@ public final class IdentityAttributeRef {
 
     @ConstructorProperties(QNAME_ATTR_NAME)
     public IdentityAttributeRef(String qNameOfIdentity) {
-        if (qNameOfIdentity == null)
+        if (qNameOfIdentity == null) {
             throw new NullPointerException("Parameter " + QNAME_ATTR_NAME + " is null");
+        }
         this.qNameOfIdentity = qNameOfIdentity;
     }
 
@@ -46,12 +47,18 @@ public final class IdentityAttributeRef {
 
     @Override
     public boolean equals(Object o) {
-        if (this == o) return true;
-        if (!(o instanceof IdentityAttributeRef)) return false;
+        if (this == o) {
+            return true;
+        }
+        if (!(o instanceof IdentityAttributeRef)) {
+            return false;
+        }
 
         IdentityAttributeRef that = (IdentityAttributeRef) o;
 
-        if (!qNameOfIdentity.equals(that.qNameOfIdentity)) return false;
+        if (!qNameOfIdentity.equals(that.qNameOfIdentity)) {
+            return false;
+        }
 
         return true;
     }
index 96deb051ef91a1f1f4a3d629fc7984626ddf0dc9..244f22f58efdd5b1615806a2859fd50902b79172 100644 (file)
@@ -15,8 +15,9 @@ public class JmxAttribute {
     private final String attributeName;
 
     public JmxAttribute(String attributeName) {
-        if (attributeName == null)
+        if (attributeName == null) {
             throw new NullPointerException("Parameter 'attributeName' is null");
+        }
         this.attributeName = attributeName;
     }
 
@@ -26,16 +27,19 @@ public class JmxAttribute {
 
     @Override
     public boolean equals(Object o) {
-        if (this == o)
+        if (this == o) {
             return true;
-        if (o == null || getClass() != o.getClass())
+        }
+        if (o == null || getClass() != o.getClass()) {
             return false;
+        }
 
         JmxAttribute that = (JmxAttribute) o;
 
         if (attributeName != null ? !attributeName.equals(that.attributeName)
-                : that.attributeName != null)
+                : that.attributeName != null) {
             return false;
+        }
 
         return true;
     }
index c654f5fe0a3c97bacb0885df0857ca804db7939f..7baaf9f6e45021bb87dced0ee189fa889767e52d 100644 (file)
@@ -14,12 +14,12 @@ public class ModuleIdentifier implements Identifier {
     private final String factoryName, instanceName;
 
     public ModuleIdentifier(String factoryName, String instanceName) {
-        if (factoryName == null)
-            throw new IllegalArgumentException(
-                    "Parameter 'factoryName' is null");
-        if (instanceName == null)
-            throw new IllegalArgumentException(
-                    "Parameter 'instanceName' is null");
+        if (factoryName == null) {
+            throw new IllegalArgumentException("Parameter 'factoryName' is null");
+        }
+        if (instanceName == null) {
+            throw new IllegalArgumentException("Parameter 'instanceName' is null");
+        }
         this.factoryName = factoryName;
         this.instanceName = instanceName;
     }
@@ -34,17 +34,21 @@ public class ModuleIdentifier implements Identifier {
 
     @Override
     public boolean equals(Object o) {
-        if (this == o)
+        if (this == o) {
             return true;
-        if (o == null || getClass() != o.getClass())
+        }
+        if (o == null || getClass() != o.getClass()) {
             return false;
+        }
 
         ModuleIdentifier that = (ModuleIdentifier) o;
 
-        if (!factoryName.equals(that.factoryName))
+        if (!factoryName.equals(that.factoryName)) {
             return false;
-        if (!instanceName.equals(that.instanceName))
+        }
+        if (!instanceName.equals(that.instanceName)) {
             return false;
+        }
 
         return true;
     }
index f27d12399528c38c144fc17ea0354c243365a1a6..a93d97c7ee50c8a28e2480c3756b5fc80761ecf7 100644 (file)
@@ -118,23 +118,30 @@ public class ValidationException extends RuntimeException {
 
         @Override
         public boolean equals(Object obj) {
-            if (this == obj)
+            if (this == obj) {
                 return true;
-            if (obj == null)
+            }
+            if (obj == null) {
                 return false;
-            if (getClass() != obj.getClass())
+            }
+            if (getClass() != obj.getClass()) {
                 return false;
+            }
             ExceptionMessageWithStackTrace other = (ExceptionMessageWithStackTrace) obj;
             if (message == null) {
-                if (other.message != null)
+                if (other.message != null) {
                     return false;
-            } else if (!message.equals(other.message))
+                }
+            } else if (!message.equals(other.message)) {
                 return false;
+            }
             if (stackTrace == null) {
-                if (other.stackTrace != null)
+                if (other.stackTrace != null) {
                     return false;
-            } else if (!stackTrace.equals(other.stackTrace))
+                }
+            } else if (!stackTrace.equals(other.stackTrace)) {
                 return false;
+            }
             return true;
         }
 
index bd53bd4e581dc7285fcd8b874fbae177a8cc13c2..4f9ea7ac6b57521697f85ca7e4cde7930601ad1e 100644 (file)
@@ -7,32 +7,27 @@
  */
 package org.opendaylight.controller.config.api.jmx;
 
+import javax.annotation.concurrent.Immutable;
+import javax.management.ObjectName;
 import java.beans.ConstructorProperties;
 import java.util.Collections;
 import java.util.List;
 
-import javax.annotation.concurrent.Immutable;
-import javax.management.ObjectName;
-
 @Immutable
 public class CommitStatus {
     private final List<ObjectName> newInstances, reusedInstances,
             recreatedInstances;
 
     /**
-     *
-     * @param newInstances
-     *            newly created instances
-     * @param reusedInstances
-     *            reused instances
-     * @param recreatedInstances
-     *            recreated instances
+     * @param newInstances       newly created instances
+     * @param reusedInstances    reused instances
+     * @param recreatedInstances recreated instances
      */
-    @ConstructorProperties({ "newInstances", "reusedInstances",
-            "recreatedInstances" })
+    @ConstructorProperties({"newInstances", "reusedInstances",
+            "recreatedInstances"})
     public CommitStatus(List<ObjectName> newInstances,
-            List<ObjectName> reusedInstances,
-            List<ObjectName> recreatedInstances) {
+                        List<ObjectName> reusedInstances,
+                        List<ObjectName> recreatedInstances) {
         this.newInstances = Collections.unmodifiableList(newInstances);
         this.reusedInstances = Collections.unmodifiableList(reusedInstances);
         this.recreatedInstances = Collections
@@ -40,7 +35,6 @@ public class CommitStatus {
     }
 
     /**
-     *
      * @return list of objectNames representing newly created instances
      */
     public List<ObjectName> getNewInstances() {
@@ -48,7 +42,6 @@ public class CommitStatus {
     }
 
     /**
-     *
      * @return list of objectNames representing reused instances
      */
     public List<ObjectName> getReusedInstances() {
@@ -56,7 +49,6 @@ public class CommitStatus {
     }
 
     /**
-     *
      * @return list of objectNames representing recreated instances
      */
     public List<ObjectName> getRecreatedInstances() {
@@ -72,7 +64,7 @@ public class CommitStatus {
         result = prime
                 * result
                 + ((recreatedInstances == null) ? 0 : recreatedInstances
-                        .hashCode());
+                .hashCode());
         result = prime * result
                 + ((reusedInstances == null) ? 0 : reusedInstances.hashCode());
         return result;
@@ -80,28 +72,37 @@ public class CommitStatus {
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
+        if (this == obj) {
             return true;
-        if (obj == null)
+        }
+        if (obj == null) {
             return false;
-        if (getClass() != obj.getClass())
+        }
+        if (getClass() != obj.getClass()) {
             return false;
+        }
         CommitStatus other = (CommitStatus) obj;
         if (newInstances == null) {
-            if (other.newInstances != null)
+            if (other.newInstances != null) {
                 return false;
-        } else if (!newInstances.equals(other.newInstances))
+            }
+        } else if (!newInstances.equals(other.newInstances)) {
             return false;
+        }
         if (recreatedInstances == null) {
-            if (other.recreatedInstances != null)
+            if (other.recreatedInstances != null) {
                 return false;
-        } else if (!recreatedInstances.equals(other.recreatedInstances))
+            }
+        } else if (!recreatedInstances.equals(other.recreatedInstances)) {
             return false;
+        }
         if (reusedInstances == null) {
-            if (other.reusedInstances != null)
+            if (other.reusedInstances != null) {
                 return false;
-        } else if (!reusedInstances.equals(other.reusedInstances))
+            }
+        } else if (!reusedInstances.equals(other.reusedInstances)) {
             return false;
+        }
         return true;
     }
 
index 3baa1039e0bd1c868c28b6d8d5f7ea35c8da3dc7..d60e6086176daebd69f58a795ccadd4f24eca4de 100644 (file)
@@ -11,6 +11,7 @@ import org.opendaylight.controller.config.api.ModuleIdentifier;
 import org.opendaylight.controller.config.api.jmx.constants.ConfigRegistryConstants;
 
 import javax.annotation.concurrent.ThreadSafe;
+import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -46,8 +47,8 @@ public class ObjectNameUtil {
     public static ObjectName createON(String on) {
         try {
             return new ObjectName(on);
-        } catch (Exception e) {
-            throw new RuntimeException(e);
+        } catch (MalformedObjectNameException e) {
+            throw new IllegalArgumentException(e);
         }
     }
 
@@ -63,8 +64,8 @@ public class ObjectNameUtil {
         Hashtable<String, String> table = new Hashtable<>(attribs);
         try {
             return new ObjectName(domain, table);
-        } catch (Exception e) {
-            throw new RuntimeException(e);
+        } catch (MalformedObjectNameException e) {
+            throw new IllegalArgumentException(e);
         }
 
     }
@@ -116,8 +117,7 @@ public class ObjectNameUtil {
     public static String getServiceQName(ObjectName objectName) {
         checkType(objectName, TYPE_SERVICE_REFERENCE);
         String quoted = objectName.getKeyProperty(SERVICE_QNAME_KEY);
-        String result = unquoteAndUnescape(objectName, quoted);
-        return result;
+        return unquoteAndUnescape(objectName, quoted);
     }
 
     // ObjectName supports quotation and ignores tokens like =, but fails to ignore ? sign.
@@ -292,8 +292,8 @@ public class ObjectNameUtil {
         }
     }
 
-    public static void checkTypeOneOf(ObjectName objectName, String ... types) {
-        for(String type: types) {
+    public static void checkTypeOneOf(ObjectName objectName, String... types) {
+        for (String type : types) {
             if (type.equals(objectName.getKeyProperty(TYPE_KEY))) {
                 return;
             }
@@ -304,10 +304,12 @@ public class ObjectNameUtil {
 
     public static ObjectName createModulePattern(String moduleName,
                                                  String instanceName) {
-        if (moduleName == null)
+        if (moduleName == null) {
             moduleName = "*";
-        if (instanceName == null)
+        }
+        if (instanceName == null) {
             instanceName = "*";
+        }
         // do not return object names containing transaction name
         ObjectName namePattern = ObjectNameUtil
                 .createON(ObjectNameUtil.ON_DOMAIN + ":"
@@ -343,13 +345,15 @@ public class ObjectNameUtil {
                                           String expectedType) {
         checkType(objectName, expectedType);
         String factoryName = getFactoryName(objectName);
-        if (factoryName == null)
+        if (factoryName == null) {
             throw new IllegalArgumentException(
                     "ObjectName does not contain module name");
+        }
         String instanceName = getInstanceName(objectName);
-        if (instanceName == null)
+        if (instanceName == null) {
             throw new IllegalArgumentException(
                     "ObjectName does not contain instance name");
+        }
         return new ModuleIdentifier(factoryName, instanceName);
     }
 
index 81a29bf7b3198215bcba9eb5a92732df3238f77d..1d9563bf4e1d7733b170cdd6c092f473a8baae20 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.controller.config.api.jmx.constants;
 
+import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
 public class ConfigRegistryConstants {
@@ -19,7 +20,7 @@ public class ConfigRegistryConstants {
 
     public static final ObjectName OBJECT_NAME = createONWithDomainAndType(TYPE_CONFIG_REGISTRY);
 
-    public static String GET_AVAILABLE_MODULE_NAMES_ATTRIBUT_NAME = "AvailableModuleNames";
+    public static final String GET_AVAILABLE_MODULE_NAMES_ATTRIBUT_NAME = "AvailableModuleNames";
 
     public static ObjectName createONWithDomainAndType(String type) {
         return createON(ON_DOMAIN, TYPE_KEY, type);
@@ -28,8 +29,8 @@ public class ConfigRegistryConstants {
     public static ObjectName createON(String name, String key, String value) {
         try {
             return new ObjectName(name, key, value);
-        } catch (Exception e) {
-            throw new RuntimeException(e);
+        } catch (MalformedObjectNameException e) {
+            throw new IllegalArgumentException(e);
         }
 
     }
index 39682fa6b470226400b47a6aa0fdbec24a4bf522..8f6a4654b26d2d9f2548c38e91ea9b82445b326f 100644 (file)
@@ -105,27 +105,27 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe
     private List<ModuleFactory> lastListOfFactories = Collections.emptyList();
 
     @GuardedBy("this") // switched in every 2ndPC
-    private CloseableServiceReferenceReadableRegistry  readableSRRegistry = ServiceReferenceRegistryImpl.createInitialSRLookupRegistry();
+    private CloseableServiceReferenceReadableRegistry readableSRRegistry = ServiceReferenceRegistryImpl.createInitialSRLookupRegistry();
 
     // constructor
     public ConfigRegistryImpl(ModuleFactoriesResolver resolver,
-            MBeanServer configMBeanServer, CodecRegistry codecRegistry) {
+                              MBeanServer configMBeanServer, CodecRegistry codecRegistry) {
         this(resolver, configMBeanServer,
                 new BaseJMXRegistrator(configMBeanServer), codecRegistry);
     }
 
     // constructor
     public ConfigRegistryImpl(ModuleFactoriesResolver resolver,
-            MBeanServer configMBeanServer,
-            BaseJMXRegistrator baseJMXRegistrator, CodecRegistry codecRegistry) {
+                              MBeanServer configMBeanServer,
+                              BaseJMXRegistrator baseJMXRegistrator, CodecRegistry codecRegistry) {
         this.resolver = resolver;
-        this.beanToOsgiServiceManager = new BeanToOsgiServiceManager();
+        beanToOsgiServiceManager = new BeanToOsgiServiceManager();
         this.configMBeanServer = configMBeanServer;
         this.baseJMXRegistrator = baseJMXRegistrator;
         this.codecRegistry = codecRegistry;
-        this.registryMBeanServer = MBeanServerFactory
+        registryMBeanServer = MBeanServerFactory
                 .createMBeanServer("ConfigRegistry" + configMBeanServer.getDefaultDomain());
-        this.transactionsMBeanServer = MBeanServerFactory
+        transactionsMBeanServer = MBeanServerFactory
                 .createMBeanServer("ConfigTransactions" + configMBeanServer.getDefaultDomain());
     }
 
@@ -181,6 +181,7 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe
      * {@inheritDoc}
      */
     @Override
+    @SuppressWarnings("PMD.AvoidCatchingThrowable")
     public synchronized CommitStatus commitConfig(ObjectName transactionControllerON)
             throws ConflictingVersionException, ValidationException {
         final String transactionName = ObjectNameUtil
@@ -211,7 +212,7 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe
             return secondPhaseCommit(
                     configTransactionController, commitInfo);
         } catch (Throwable t) { // some libs throw Errors: e.g.
-                                // javax.xml.ws.spi.FactoryFinder$ConfigurationError
+            // javax.xml.ws.spi.FactoryFinder$ConfigurationError
             isHealthy = false;
             logger.error("Configuration Transaction failed on 2PC, server is unhealthy", t);
             if (t instanceof RuntimeException) {
@@ -219,7 +220,7 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe
             } else if (t instanceof Error) {
                 throw (Error) t;
             } else {
-                throw new RuntimeException(t);
+                throw new IllegalStateException(t);
             }
         }
     }
@@ -232,7 +233,7 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe
         for (DestroyedModule toBeDestroyed : commitInfo
                 .getDestroyedFromPreviousTransactions()) {
             toBeDestroyed.close(); // closes instance (which should close
-                                   // runtime jmx registrator),
+            // runtime jmx registrator),
             // also closes osgi registration and ModuleJMXRegistrator
             // registration
             currentConfig.remove(toBeDestroyed.getIdentifier());
@@ -278,9 +279,10 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe
         for (ModuleIdentifier moduleIdentifier : orderedModuleIdentifiers) {
             ModuleInternalTransactionalInfo entry = commitInfo.getCommitted()
                     .get(moduleIdentifier);
-            if (entry == null)
+            if (entry == null) {
                 throw new NullPointerException("Module not found "
                         + moduleIdentifier);
+            }
             Module module = entry.getModule();
             ObjectName primaryReadOnlyON = ObjectNameUtil
                     .createReadOnlyModuleON(moduleIdentifier);
@@ -342,7 +344,7 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe
             // register to OSGi
             if (osgiRegistration == null) {
                 ModuleFactory moduleFactory = entry.getModuleFactory();
-                if(moduleFactory != null) {
+                if (moduleFactory != null) {
                     BundleContext bc = configTransactionController.
                             getModuleFactoryBundleContext(moduleFactory.getImplementationName());
                     osgiRegistration = beanToOsgiServiceManager.registerToOsgi(module.getClass(),
@@ -369,8 +371,8 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe
         version = configTransactionController.getVersion();
 
         // switch readable Service Reference Registry
-        this.readableSRRegistry.close();
-        this.readableSRRegistry = ServiceReferenceRegistryImpl.createSRReadableRegistry(
+        readableSRRegistry.close();
+        readableSRRegistry = ServiceReferenceRegistryImpl.createSRReadableRegistry(
                 configTransactionController.getWritableRegistry(), this, baseJMXRegistrator);
 
         return new CommitStatus(newInstances, reusedInstances,
@@ -485,7 +487,7 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe
      */
     @Override
     public Set<ObjectName> lookupConfigBeans(String moduleName,
-            String instanceName) {
+                                             String instanceName) {
         ObjectName namePattern = ObjectNameUtil.createModulePattern(moduleName,
                 instanceName);
         return baseJMXRegistrator.queryNames(namePattern, null);
@@ -504,11 +506,13 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe
      */
     @Override
     public Set<ObjectName> lookupRuntimeBeans(String moduleName,
-            String instanceName) {
-        if (moduleName == null)
+                                              String instanceName) {
+        if (moduleName == null) {
             moduleName = "*";
-        if (instanceName == null)
+        }
+        if (instanceName == null) {
             instanceName = "*";
+        }
         ObjectName namePattern = ObjectNameUtil.createRuntimeBeanPattern(
                 moduleName, instanceName);
         return baseJMXRegistrator.queryNames(namePattern, null);
@@ -646,7 +650,6 @@ class TransactionsHolder {
      * {@link ConfigTransactionControllerInternal} instances, because platform
      * MBeanServer transforms mbeans into another representation. Map is cleaned
      * every time current transactions are requested.
-     *
      */
     @GuardedBy("ConfigRegistryImpl.this")
     private final Map<String /* transactionName */, ConfigTransactionControllerInternal> transactions = new HashMap<>();
@@ -655,7 +658,7 @@ class TransactionsHolder {
      * Can only be called from within synchronized method.
      */
     public void add(String transactionName,
-            ConfigTransactionControllerInternal transactionController) {
+                    ConfigTransactionControllerInternal transactionController) {
         Object oldValue = transactions.put(transactionName,
                 transactionController);
         if (oldValue != null) {
@@ -674,7 +677,7 @@ class TransactionsHolder {
     public Map<String, ConfigTransactionControllerInternal> getCurrentTransactions() {
         // first, remove closed transaction
         for (Iterator<Entry<String, ConfigTransactionControllerInternal>> it = transactions
-                .entrySet().iterator(); it.hasNext();) {
+                .entrySet().iterator(); it.hasNext(); ) {
             Entry<String, ConfigTransactionControllerInternal> entry = it
                     .next();
             if (entry.getValue().isClosed()) {
index 0ec6969802438b2c8e71856bf64cdeeb7fbcfb74..f7afded51ff0c81468b0678c0b964485cd1b0b8c 100644 (file)
@@ -53,7 +53,7 @@ import static java.lang.String.format;
 class ConfigTransactionControllerImpl implements
         ConfigTransactionControllerInternal,
         ConfigTransactionControllerImplMXBean,
-        Identifiable<TransactionIdentifier>{
+        Identifiable<TransactionIdentifier> {
     private static final Logger logger = LoggerFactory.getLogger(ConfigTransactionControllerImpl.class);
 
     private final ConfigTransactionLookupRegistry txLookupRegistry;
@@ -124,12 +124,12 @@ class ConfigTransactionControllerImpl implements
 
         List<ModuleFactory> toBeAdded = new ArrayList<>();
         List<ModuleFactory> toBeRemoved = new ArrayList<>();
-        for(ModuleFactory moduleFactory: factoriesHolder.getModuleFactories()) {
-            if (oldSet.contains(moduleFactory) == false){
+        for (ModuleFactory moduleFactory : factoriesHolder.getModuleFactories()) {
+            if (oldSet.contains(moduleFactory) == false) {
                 toBeAdded.add(moduleFactory);
             }
         }
-        for(ModuleFactory moduleFactory: lastListOfFactories){
+        for (ModuleFactory moduleFactory : lastListOfFactories) {
             if (newSet.contains(moduleFactory) == false) {
                 toBeRemoved.add(moduleFactory);
             }
@@ -151,7 +151,7 @@ class ConfigTransactionControllerImpl implements
         }
 
         // remove modules belonging to removed factories
-        for(ModuleFactory removedFactory: toBeRemoved){
+        for (ModuleFactory removedFactory : toBeRemoved) {
             List<ModuleIdentifier> modulesOfRemovedFactory = dependencyResolverManager.findAllByFactory(removedFactory);
             for (ModuleIdentifier name : modulesOfRemovedFactory) {
                 destroyModule(name);
@@ -189,7 +189,7 @@ class ConfigTransactionControllerImpl implements
 
     @Override
     public synchronized ObjectName createModule(String factoryName,
-            String instanceName) throws InstanceAlreadyExistsException {
+                                                String instanceName) throws InstanceAlreadyExistsException {
 
         transactionStatus.checkNotCommitStarted();
         transactionStatus.checkNotAborted();
@@ -213,11 +213,11 @@ class ConfigTransactionControllerImpl implements
             throws InstanceAlreadyExistsException {
 
         logger.debug("Adding module {} to transaction {}", moduleIdentifier, this);
-        if (moduleIdentifier.equals(module.getIdentifier())==false) {
+        if (moduleIdentifier.equals(module.getIdentifier()) == false) {
             throw new IllegalStateException("Incorrect name reported by module. Expected "
-             + moduleIdentifier + ", got " + module.getIdentifier());
+                    + moduleIdentifier + ", got " + module.getIdentifier());
         }
-        if (dependencyResolver.getIdentifier().equals(moduleIdentifier) == false ) {
+        if (dependencyResolver.getIdentifier().equals(moduleIdentifier) == false) {
             throw new IllegalStateException("Incorrect name reported by dependency resolver. Expected "
                     + moduleIdentifier + ", got " + dependencyResolver.getIdentifier());
         }
@@ -271,7 +271,7 @@ class ConfigTransactionControllerImpl implements
         // first remove refNames, it checks for objectname existence
         try {
             writableSRRegistry.removeServiceReferences(
-                    ObjectNameUtil.createTransactionModuleON(getTransactionName(),moduleIdentifier));
+                    ObjectNameUtil.createTransactionModuleON(getTransactionName(), moduleIdentifier));
         } catch (InstanceNotFoundException e) {
             logger.error("Possible code error: cannot find {} in {}", moduleIdentifier, writableSRRegistry);
             throw new IllegalStateException("Possible code error: cannot find " + moduleIdentifier, e);
@@ -294,8 +294,9 @@ class ConfigTransactionControllerImpl implements
 
     @Override
     public synchronized void validateConfig() throws ValidationException {
-        if (configBeanModificationDisabled.get())
+        if (configBeanModificationDisabled.get()) {
             throw new IllegalStateException("Cannot start validation");
+        }
         configBeanModificationDisabled.set(true);
         try {
             validate_noLocks();
@@ -383,7 +384,7 @@ class ConfigTransactionControllerImpl implements
                 logger.error("Commit failed on {} in transaction {}", name,
                         getTransactionIdentifier(), e);
                 internalAbort();
-                throw new RuntimeException(
+                throw new IllegalStateException(
                         format("Error - getInstance() failed for %s in transaction %s",
                                 name, getTransactionIdentifier()), e);
             }
index 0a4ceacb439c363a5884b0e2296089d6f10ab6ef..f5984334331ec2d7eb9d8c0d6bb07cfd1bc5f030 100644 (file)
@@ -7,16 +7,15 @@
  */
 package org.opendaylight.controller.config.manager.impl;
 
-import javax.annotation.Nullable;
-
 import org.opendaylight.controller.config.api.ModuleIdentifier;
 import org.opendaylight.controller.config.manager.impl.dynamicmbean.DynamicReadableWrapper;
-import org.opendaylight.controller.config.manager.impl.jmx.TransactionModuleJMXRegistrator
-        .TransactionModuleJMXRegistration;
+import org.opendaylight.controller.config.manager.impl.jmx.TransactionModuleJMXRegistrator.TransactionModuleJMXRegistration;
 import org.opendaylight.controller.config.spi.Module;
 import org.opendaylight.controller.config.spi.ModuleFactory;
 import org.opendaylight.yangtools.concepts.Identifiable;
 
+import javax.annotation.Nullable;
+
 public class ModuleInternalTransactionalInfo implements Identifiable<ModuleIdentifier> {
     private final ModuleIdentifier name;
     private final Module module;
@@ -27,10 +26,10 @@ public class ModuleInternalTransactionalInfo implements Identifiable<ModuleIdent
     private final boolean isDefaultBean;
 
     ModuleInternalTransactionalInfo(ModuleIdentifier name, Module module,
-            ModuleFactory moduleFactory,
-            ModuleInternalInfo maybeOldInternalInfo,
-            TransactionModuleJMXRegistration transactionModuleJMXRegistration,
-            boolean isDefaultBean) {
+                                    ModuleFactory moduleFactory,
+                                    ModuleInternalInfo maybeOldInternalInfo,
+                                    TransactionModuleJMXRegistration transactionModuleJMXRegistration,
+                                    boolean isDefaultBean) {
         this.name = name;
         this.module = module;
         this.moduleFactory = moduleFactory;
@@ -67,8 +66,9 @@ public class ModuleInternalTransactionalInfo implements Identifiable<ModuleIdent
 
     @Nullable
     public ModuleInternalInfo getOldInternalInfo() {
-        if (maybeOldInternalInfo == null)
+        if (maybeOldInternalInfo == null) {
             throw new NullPointerException();
+        }
         return maybeOldInternalInfo;
     }
 
index 0faa32b7dc4e181962802d8d5e1345472d8378d9..bf35fd1ed86f6b8249dcb4a7ca386d85ad2a53d1 100644 (file)
@@ -195,7 +195,7 @@ public class ServiceReferenceRegistryImpl implements CloseableServiceReferenceRe
 
         this.serviceReferenceRegistrator = serviceReferenceRegistratorFactory.create();
 
-        Map<String, Set<String /* QName */>> factoryNamesToQNames = new HashMap<>();
+        Map<String, Set<String /* QName */>> modifiableFactoryNamesToQNames = new HashMap<>();
         Set<ServiceInterfaceAnnotation> allAnnotations = new HashSet<>();
         Set<String /* qName */> allQNames = new HashSet<>();
         for (Entry<String, ModuleFactory> entry : factories.entrySet()) {
@@ -210,27 +210,27 @@ public class ServiceReferenceRegistryImpl implements CloseableServiceReferenceRe
             }
             allAnnotations.addAll(siAnnotations);
             allQNames.addAll(qNames);
-            factoryNamesToQNames.put(entry.getKey(), Collections.unmodifiableSet(qNames));
+            modifiableFactoryNamesToQNames.put(entry.getKey(), Collections.unmodifiableSet(qNames));
         }
-        this.factoryNamesToQNames = Collections.unmodifiableMap(factoryNamesToQNames);
+        this.factoryNamesToQNames = Collections.unmodifiableMap(modifiableFactoryNamesToQNames);
         this.allQNames = Collections.unmodifiableSet(allQNames);
         // fill namespacesToAnnotations
-        Map<String /* namespace */, Map<String /* localName */, ServiceInterfaceAnnotation>> namespacesToAnnotations =
+        Map<String /* namespace */, Map<String /* localName */, ServiceInterfaceAnnotation>> modifiableNamespacesToAnnotations =
                 new HashMap<>();
         for (ServiceInterfaceAnnotation sia : allAnnotations) {
-            Map<String, ServiceInterfaceAnnotation> ofNamespace = namespacesToAnnotations.get(sia.namespace());
+            Map<String, ServiceInterfaceAnnotation> ofNamespace = modifiableNamespacesToAnnotations.get(sia.namespace());
             if (ofNamespace == null) {
                 ofNamespace = new HashMap<>();
-                namespacesToAnnotations.put(sia.namespace(), ofNamespace);
+                modifiableNamespacesToAnnotations.put(sia.namespace(), ofNamespace);
             }
             if (ofNamespace.containsKey(sia.localName())) {
                 logger.error("Cannot construct namespacesToAnnotations map, conflict between local names in {}, offending local name: {}, map so far {}",
-                        sia.namespace(), sia.localName(), namespacesToAnnotations);
+                        sia.namespace(), sia.localName(), modifiableNamespacesToAnnotations);
                 throw new IllegalArgumentException("Conflict between local names in " + sia.namespace() + " : " + sia.localName());
             }
             ofNamespace.put(sia.localName(), sia);
         }
-        this.namespacesToAnnotations = Collections.unmodifiableMap(namespacesToAnnotations);
+        this.namespacesToAnnotations = Collections.unmodifiableMap(modifiableNamespacesToAnnotations);
         // copy refNames
         logger.trace("factoryNamesToQNames:{}", this.factoryNamesToQNames);
     }
index 28bd613648d31bfcb6072737b065ceaa07bf7390..15c69bf25fe4db456ae9a7890ad389f8f953251a 100644 (file)
@@ -28,15 +28,18 @@ public class TransactionIdentifier implements Identifier {
 
     @Override
     public boolean equals(Object o) {
-        if (this == o)
+        if (this == o) {
             return true;
-        if (o == null || getClass() != o.getClass())
+        }
+        if (o == null || getClass() != o.getClass()) {
             return false;
+        }
 
         TransactionIdentifier that = (TransactionIdentifier) o;
 
-        if (name != null ? !name.equals(that.name) : that.name != null)
+        if (name != null ? !name.equals(that.name) : that.name != null) {
             return false;
+        }
 
         return true;
     }
index a25062074b8384837a46924d77dc0badc4a03eac..f86d6b1d818715481f601a4e366240aae2e5d4a5 100644 (file)
@@ -48,18 +48,21 @@ public class TransactionStatus {
     }
 
     public synchronized void checkNotCommitStarted() {
-        if (secondPhaseCommitStarted == true)
+        if (secondPhaseCommitStarted == true) {
             throw new IllegalStateException("Commit was triggered");
+        }
     }
 
     public synchronized void checkCommitStarted() {
-        if (secondPhaseCommitStarted == false)
+        if (secondPhaseCommitStarted == false) {
             throw new IllegalStateException("Commit was not triggered");
+        }
     }
 
     public synchronized void checkNotAborted() {
-        if (aborted == true)
+        if (aborted == true) {
             throw new IllegalStateException("Configuration was aborted");
+        }
     }
 
     public synchronized void checkNotCommitted() {
index ec9678fd2d7df3545f15bc5a8fa0e7b8129b5760..e3057a1179419bf6c42daafee1f48bbbd131e786 100644 (file)
@@ -39,7 +39,7 @@ import static java.lang.String.format;
  * during validation. Tracks dependencies for ordering purposes.
  */
 final class DependencyResolverImpl implements DependencyResolver,
-       Comparable<DependencyResolverImpl> {
+        Comparable<DependencyResolverImpl> {
     private static final Logger logger = LoggerFactory.getLogger(DependencyResolverImpl.class);
 
     private final ModulesHolder modulesHolder;
@@ -74,15 +74,15 @@ final class DependencyResolverImpl implements DependencyResolver,
             throw new NullPointerException(
                     "Parameter 'expectedServiceInterface' is null");
         }
-        if (jmxAttribute == null)
+        if (jmxAttribute == null) {
             throw new NullPointerException("Parameter 'jmxAttribute' is null");
+        }
 
         JmxAttributeValidationException.checkNotNull(dependentReadOnlyON,
                 "is null, expected dependency implementing "
                         + expectedServiceInterface, jmxAttribute);
 
 
-
         // check that objectName belongs to this transaction - this should be
         // stripped
         // in DynamicWritableWrapper
@@ -135,7 +135,7 @@ final class DependencyResolverImpl implements DependencyResolver,
     //TODO: check for cycles
     @Override
     public <T> T resolveInstance(Class<T> expectedType, ObjectName dependentReadOnlyON,
-            JmxAttribute jmxAttribute) {
+                                 JmxAttribute jmxAttribute) {
         if (expectedType == null || dependentReadOnlyON == null || jmxAttribute == null) {
             throw new IllegalArgumentException(format(
                     "Null parameters not allowed, got %s %s %s", expectedType,
@@ -161,8 +161,7 @@ final class DependencyResolverImpl implements DependencyResolver,
             throw new JmxAttributeValidationException(message, jmxAttribute);
         }
         try {
-            T result = expectedType.cast(instance);
-            return result;
+            return expectedType.cast(instance);
         } catch (ClassCastException e) {
             String message = format(
                     "Instance cannot be cast to expected type. Instance class is %s , "
@@ -178,7 +177,7 @@ final class DependencyResolverImpl implements DependencyResolver,
         IdentityCodec<?> identityCodec = codecRegistry.getIdentityCodec();
         Class<? extends BaseIdentity> deserialized = identityCodec.deserialize(qName);
         if (deserialized == null) {
-            throw new RuntimeException("Unable to retrieve identity class for " + qName + ", null response from "
+            throw new IllegalStateException("Unable to retrieve identity class for " + qName + ", null response from "
                     + codecRegistry);
         }
         if (expectedBaseClass.isAssignableFrom(deserialized)) {
@@ -194,7 +193,7 @@ final class DependencyResolverImpl implements DependencyResolver,
     public <T extends BaseIdentity> void validateIdentity(IdentityAttributeRef identityRef, Class<T> expectedBaseClass, JmxAttribute jmxAttribute) {
         try {
             resolveIdentity(identityRef, expectedBaseClass);
-        } catch(Exception e) {
+        } catch (Exception e) {
             throw JmxAttributeValidationException.wrap(e, jmxAttribute);
         }
     }
@@ -224,8 +223,8 @@ final class DependencyResolverImpl implements DependencyResolver,
     }
 
     private static int getMaxDepth(DependencyResolverImpl impl,
-            DependencyResolverManager manager,
-            LinkedHashSet<ModuleIdentifier> chainForDetectingCycles) {
+                                   DependencyResolverManager manager,
+                                   LinkedHashSet<ModuleIdentifier> chainForDetectingCycles) {
         int maxDepth = 0;
         LinkedHashSet<ModuleIdentifier> chainForDetectingCycles2 = new LinkedHashSet<>(
                 chainForDetectingCycles);
index 6f0d1b2682a00e17b8935cca72c86599cd2b2b63..7e48af1caae9adc31cb0c76b64a86d0fb7bca428 100644 (file)
@@ -55,7 +55,6 @@ import static java.lang.String.format;
  * requests (getAttribute, setAttribute, invoke) into the actual instance, but
  * provides additional functionality - namely it disallows setting attribute on
  * a read only wrapper.
- *
  */
 abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
     private static final Logger logger = LoggerFactory
@@ -71,9 +70,9 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
     protected final MBeanServer internalServer;
 
     public AbstractDynamicWrapper(Module module, boolean writable,
-            ModuleIdentifier moduleIdentifier,
-            ObjectName thisWrapperObjectName, MBeanOperationInfo[] dOperations,
-            MBeanServer internalServer, MBeanServer configMBeanServer) {
+                                  ModuleIdentifier moduleIdentifier,
+                                  ObjectName thisWrapperObjectName, MBeanOperationInfo[] dOperations,
+                                  MBeanServer internalServer, MBeanServer configMBeanServer) {
 
         this.writable = writable;
         this.module = module;
@@ -98,10 +97,10 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
      * case unregister the module and remove listener.
      */
     private final NotificationListener registerActualModule(Module module,
-            final ObjectName thisWrapperObjectName,
-            final ObjectName objectNameInternal,
-            final MBeanServer internalServer,
-            final MBeanServer configMBeanServer) {
+                                                            final ObjectName thisWrapperObjectName,
+                                                            final ObjectName objectNameInternal,
+                                                            final MBeanServer internalServer,
+                                                            final MBeanServer configMBeanServer) {
 
         try {
             internalServer.registerMBean(module, objectNameInternal);
@@ -116,7 +115,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
             public void handleNotification(Notification n, Object handback) {
                 if (n instanceof MBeanServerNotification
                         && n.getType()
-                                .equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
+                        .equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
                     if (((MBeanServerNotification) n).getMBeanName().equals(
                             thisWrapperObjectName)) {
                         try {
@@ -142,8 +141,8 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
     }
 
     private static MBeanInfo generateMBeanInfo(String className, Module module,
-            Map<String, AttributeHolder> attributeHolderMap,
-            MBeanOperationInfo[] dOperations, Set<Class<?>> jmxInterfaces) {
+                                               Map<String, AttributeHolder> attributeHolderMap,
+                                               MBeanOperationInfo[] dOperations, Set<Class<?>> jmxInterfaces) {
 
         String dDescription = findDescription(module.getClass(), jmxInterfaces);
         MBeanConstructorInfo[] dConstructors = new MBeanConstructorInfo[0];
@@ -170,9 +169,9 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
     // inspect all exported interfaces ending with MXBean, extract getters &
     // setters into attribute holder
     private static Map<String, AttributeHolder> buildMBeanInfo(Module module,
-            boolean writable, ModuleIdentifier moduleIdentifier,
-            Set<Class<?>> jmxInterfaces, MBeanServer internalServer,
-            ObjectName internalObjectName) {
+                                                               boolean writable, ModuleIdentifier moduleIdentifier,
+                                                               Set<Class<?>> jmxInterfaces, MBeanServer internalServer,
+                                                               ObjectName internalObjectName) {
 
         // internal variables for describing MBean elements
         Set<Method> methods = new HashSet<>();
@@ -217,7 +216,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
                 }
                 AttributeHolder attributeHolder = new AttributeHolder(
                         attribName, module, attributeMap.get(attribName)
-                                .getType(), writable, ifc, description);
+                        .getType(), writable, ifc, description);
                 attributeHolderMap.put(attribName, attributeHolder);
             }
         }
@@ -257,7 +256,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
         }
 
 
-        if(isDependencyListAttr(attributeName, obj)) {
+        if (isDependencyListAttr(attributeName, obj)) {
             obj = fixDependencyListAttribute(obj);
         }
 
@@ -265,14 +264,16 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
     }
 
     private Object fixDependencyListAttribute(Object attribute) {
-        if(attribute.getClass().isArray() == false)
+        if (attribute.getClass().isArray() == false) {
             throw new IllegalArgumentException("Unexpected attribute type, should be an array, but was " + attribute.getClass());
+        }
 
         for (int i = 0; i < Array.getLength(attribute); i++) {
 
             Object on = Array.get(attribute, i);
-            if(on instanceof ObjectName == false)
+            if (on instanceof ObjectName == false) {
                 throw new IllegalArgumentException("Unexpected attribute type, should be an ObjectName, but was " + on.getClass());
+            }
             on = fixObjectName((ObjectName) on);
 
             Array.set(attribute, i, on);
@@ -282,8 +283,9 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
     }
 
     private boolean isDependencyListAttr(String attributeName, Object attribute) {
-        if (attributeHolderMap.containsKey(attributeName) == false)
+        if (attributeHolderMap.containsKey(attributeName) == false) {
             return false;
+        }
 
         AttributeHolder attributeHolder = attributeHolderMap.get(attributeName);
 
@@ -294,15 +296,17 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
     }
 
     protected ObjectName fixObjectName(ObjectName on) {
-        if (!ObjectNameUtil.ON_DOMAIN.equals(on.getDomain()))
+        if (!ObjectNameUtil.ON_DOMAIN.equals(on.getDomain())) {
             throw new IllegalArgumentException("Wrong domain, expected "
                     + ObjectNameUtil.ON_DOMAIN + " setter on " + on);
+        }
         // if on contains transaction name, remove it
         String transactionName = ObjectNameUtil.getTransactionName(on);
-        if (transactionName != null)
+        if (transactionName != null) {
             return ObjectNameUtil.withoutTransactionName(on);
-        else
+        } else {
             return on;
+        }
     }
 
     @Override
index 64664f79802bc62b10f7e895df7efe36418effe0..f3e1b4e705c3b943230d13ee52eca44bd798b930 100644 (file)
@@ -7,15 +7,15 @@
  */
 package org.opendaylight.controller.config.manager.impl.dynamicmbean;
 
+import org.opendaylight.controller.config.api.annotations.Description;
+
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
 
-import org.opendaylight.controller.config.api.annotations.Description;
-
-class AnnotationsHelper {
+public class AnnotationsHelper {
 
     /**
      * Look for annotation specified by annotationType on method. First observe
index 9dd6a2269e259cf4ca5ee4e6b1331d85ef015d81..044f7a9ada06af871fad5bc1cad531e550bab8c8 100644 (file)
@@ -40,9 +40,9 @@ class AttributeHolder {
     }
 
     public AttributeHolder(String name, Object object, String returnType,
-            boolean writable,
-            @Nullable RequireInterface requireInterfaceAnnotation,
-            String description) {
+                           boolean writable,
+                           @Nullable RequireInterface requireInterfaceAnnotation,
+                           String description) {
         if (name == null) {
             throw new NullPointerException();
         }
@@ -65,7 +65,7 @@ class AttributeHolder {
 
     /**
      * @return annotation if setter sets ObjectName or ObjectName[], and is
-     *         annotated. Return null otherwise.
+     * annotated. Return null otherwise.
      */
     RequireInterface getRequireInterfaceOrNull() {
         return requireInterfaceAnnotation;
@@ -98,7 +98,7 @@ class AttributeHolder {
      * @param setter
      * @param jmxInterfaces
      * @return empty string if no annotation is found, or list of descriptions
-     *         separated by newline
+     * separated by newline
      */
     static String findDescription(Method setter, Set<Class<?>> jmxInterfaces) {
         List<Description> descriptions = AnnotationsHelper
@@ -112,21 +112,21 @@ class AttributeHolder {
      *
      * @param setter
      * @param inspectedInterfaces
-     * @throws IllegalStateException
-     *             if more than one value is specified by found annotations
-     * @throws IllegalArgumentException
-     *             if set of exported interfaces contains non interface type
      * @return null if no annotation is found, otherwise return the annotation
+     * @throws IllegalStateException    if more than one value is specified by found annotations
+     * @throws IllegalArgumentException if set of exported interfaces contains non interface type
      */
     static RequireInterface findRequireInterfaceAnnotation(final Method setter,
-            Set<Class<?>> inspectedInterfaces) {
+                                                           Set<Class<?>> inspectedInterfaces) {
 
         // only allow setX(ObjectName y) or setX(ObjectName[] y) or setX(List<ObjectName> y) to continue
 
-        if (setter.getParameterTypes().length > 1)
+        if (setter.getParameterTypes().length > 1) {
             return null;
-        if(PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER.contains(setter.getParameterTypes()[0]) == false)
+        }
+        if (PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER.contains(setter.getParameterTypes()[0]) == false) {
             return null;
+        }
 
         List<RequireInterface> foundRequireInterfaces = AnnotationsHelper
                 .findMethodAnnotationInSuperClassesAndIfcs(setter, RequireInterface.class, inspectedInterfaces);
index 16f7cf024a40958118467641736eae6ebecfcd98..adc8168af5d85b0aee22e717cb59cda7b8939b8f 100644 (file)
@@ -10,25 +10,21 @@ package org.opendaylight.controller.config.manager.impl.factoriesresolver;
 
 import org.opendaylight.controller.config.spi.ModuleFactory;
 import org.osgi.framework.BundleContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
-import java.util.Map.Entry;
-import java.util.Set;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
-import java.util.Collections;
+import java.util.Map.Entry;
+import java.util.Set;
 import java.util.TreeSet;
-import java.util.Collection;
-import java.util.ArrayList;
 
 /**
  * Hold sorted ConfigMBeanFactories by their module names. Check that module
  * names are globally unique.
  */
 public class HierarchicalConfigMBeanFactoriesHolder {
-    private static final Logger logger = LoggerFactory
-            .getLogger(HierarchicalConfigMBeanFactoriesHolder.class);
 
     private final Map<String, Map.Entry<ModuleFactory, BundleContext>> moduleNamesToConfigBeanFactories;
     private final Set<String> moduleNames;
index 5d771560a53b5dd25a3ec2140b5c2bf74f1791c0..98f0908dc710cf40fbb93b88004d411d03f594fd 100644 (file)
@@ -7,22 +7,24 @@
  */
 package org.opendaylight.controller.config.manager.impl.jmx;
 
-import java.io.Closeable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.annotation.concurrent.GuardedBy;
 import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
 import javax.management.JMX;
+import javax.management.MBeanRegistrationException;
 import javax.management.MBeanServer;
+import javax.management.NotCompliantMBeanException;
 import javax.management.ObjectName;
 import javax.management.QueryExp;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import java.io.Closeable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 public class InternalJMXRegistrator implements Closeable {
     private static final Logger logger = LoggerFactory
@@ -38,7 +40,7 @@ public class InternalJMXRegistrator implements Closeable {
         private final ObjectName on;
 
         InternalJMXRegistration(InternalJMXRegistrator internalJMXRegistrator,
-                ObjectName on) {
+                                ObjectName on) {
             this.internalJMXRegistrator = internalJMXRegistrator;
             this.on = on;
         }
@@ -54,13 +56,11 @@ public class InternalJMXRegistrator implements Closeable {
     private final List<InternalJMXRegistrator> children = new ArrayList<>();
 
     public synchronized InternalJMXRegistration registerMBean(Object object,
-            ObjectName on) throws InstanceAlreadyExistsException {
+                                                              ObjectName on) throws InstanceAlreadyExistsException {
         try {
             configMBeanServer.registerMBean(object, on);
-        } catch (InstanceAlreadyExistsException e) {
-            throw e;
-        } catch (Exception e) {
-            throw new RuntimeException(e);
+        } catch (MBeanRegistrationException | NotCompliantMBeanException e) {
+            throw new IllegalStateException(e);
         }
         registeredObjectNames.add(on);
         return new InternalJMXRegistration(this, on);
@@ -69,14 +69,13 @@ public class InternalJMXRegistrator implements Closeable {
     private synchronized void unregisterMBean(ObjectName on) {
         // first check that on was registered using this instance
         boolean removed = registeredObjectNames.remove(on);
-        if (!removed)
-            throw new IllegalStateException(
-                    "Cannot unregister - ObjectName not found in 'registeredObjectNames': "
-                            + on);
+        if (!removed) {
+            throw new IllegalStateException("Cannot unregister - ObjectName not found in 'registeredObjectNames': " + on);
+        }
         try {
             configMBeanServer.unregisterMBean(on);
-        } catch (Exception e) {
-            throw new RuntimeException(e);
+        } catch (InstanceNotFoundException | MBeanRegistrationException e) {
+            throw new IllegalStateException(e);
         }
     }
 
@@ -112,7 +111,7 @@ public class InternalJMXRegistrator implements Closeable {
     }
 
     public <T> T newMBeanProxy(ObjectName objectName, Class<T> interfaceClass,
-            boolean notificationBroadcaster) {
+                               boolean notificationBroadcaster) {
         return JMX.newMBeanProxy(configMBeanServer, objectName, interfaceClass,
                 notificationBroadcaster);
     }
@@ -123,7 +122,7 @@ public class InternalJMXRegistrator implements Closeable {
     }
 
     public <T> T newMXBeanProxy(ObjectName objectName, Class<T> interfaceClass,
-            boolean notificationBroadcaster) {
+                                boolean notificationBroadcaster) {
         return JMX.newMXBeanProxy(configMBeanServer, objectName,
                 interfaceClass, notificationBroadcaster);
     }
index 849f75234f05ccec20361066de8140ef37a5659e..cd74ddf7565a32fd74e650cde1d50e720966d506 100644 (file)
@@ -25,13 +25,21 @@ public class ServiceReference {
 
     @Override
     public boolean equals(Object o) {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
 
         ServiceReference that = (ServiceReference) o;
 
-        if (!refName.equals(that.refName)) return false;
-        if (!serviceInterfaceName.equals(that.serviceInterfaceName)) return false;
+        if (!refName.equals(that.refName)) {
+            return false;
+        }
+        if (!serviceInterfaceName.equals(that.serviceInterfaceName)) {
+            return false;
+        }
 
         return true;
     }
index b371c3f1709c3160bc2c2a372f0d7647dec24253..6fd2a2fc65201ea0d48c974875e2fe9477300ac0 100644 (file)
@@ -7,15 +7,14 @@
  */
 package org.opendaylight.controller.config.manager.impl.jmx;
 
-import java.io.Closeable;
-import java.util.Set;
+import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
+import org.opendaylight.controller.config.manager.impl.jmx.InternalJMXRegistrator.InternalJMXRegistration;
 
 import javax.management.InstanceAlreadyExistsException;
 import javax.management.ObjectName;
 import javax.management.QueryExp;
-
-import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
-import org.opendaylight.controller.config.manager.impl.jmx.InternalJMXRegistrator.InternalJMXRegistration;
+import java.io.Closeable;
+import java.util.Set;
 
 /**
  * Contains constraints on passed {@link ObjectName} parameters. Only allow (un)
@@ -26,7 +25,7 @@ public class TransactionJMXRegistrator implements Closeable {
     private final String transactionName;
 
     TransactionJMXRegistrator(InternalJMXRegistrator internalJMXRegistrator,
-            String transactionName) {
+                              String transactionName) {
         this.childJMXRegistrator = internalJMXRegistrator.createChild();
         this.transactionName = transactionName;
     }
@@ -46,10 +45,11 @@ public class TransactionJMXRegistrator implements Closeable {
 
     public TransactionJMXRegistration registerMBean(Object object, ObjectName on)
             throws InstanceAlreadyExistsException {
-        if (!transactionName.equals(ObjectNameUtil.getTransactionName(on)))
+        if (!transactionName.equals(ObjectNameUtil.getTransactionName(on))) {
             throw new IllegalArgumentException(
                     "Transaction name mismatch between expected "
                             + transactionName + " " + "and " + on);
+        }
         ObjectNameUtil.checkType(on, ObjectNameUtil.TYPE_CONFIG_TRANSACTION);
         return new TransactionJMXRegistration(
                 childJMXRegistrator.registerMBean(object, on));
index 2a533ab9a3a6813ad4fed4c4dcfe4a5dbcec2cf6..1e94e5e9c021b1660e02a6d8303333832716ad44 100644 (file)
@@ -53,7 +53,7 @@ public class BundleContextBackedModuleFactoriesResolver implements
             if(factory == null) {
                 throw new NullPointerException("ServiceReference of class" + serviceReference.getClass() + "not found.");
             }
-            StringBuffer errors = new StringBuffer();
+
             String moduleName = factory.getImplementationName();
             if (moduleName == null || moduleName.isEmpty()) {
                 throw new IllegalStateException(
@@ -63,23 +63,17 @@ public class BundleContextBackedModuleFactoriesResolver implements
                 throw new NullPointerException("Bundle context of " + factory + " ModuleFactory not found.");
             }
             logger.debug("Reading factory {} {}", moduleName, factory);
-            String error = null;
+
             Map.Entry<ModuleFactory, BundleContext> conflicting = result.get(moduleName);
             if (conflicting != null) {
-                error = String
-                        .format("Module name is not unique. Found two conflicting factories with same name '%s': " +
-                                "\n\t%s\n\t%s\n", moduleName, conflicting.getKey(), factory);
-
-            }
-
-            if (error == null) {
+                String error = String
+                        .format("Module name is not unique. Found two conflicting factories with same name '%s': '%s' '%s'",
+                                moduleName, conflicting.getKey(), factory);
+                logger.error(error);
+                throw new IllegalArgumentException(error);
+            } else {
                 result.put(moduleName, new AbstractMap.SimpleImmutableEntry<>(factory,
                         serviceReference.getBundle().getBundleContext()));
-            } else {
-                errors.append(error);
-            }
-            if (errors.length() > 0) {
-                throw new IllegalArgumentException(errors.toString());
             }
         }
         return result;
index d464cb9006af15b24de4e1e517f57883a893fd47..02cc5ea1e4a01681e9c6b2fe73b435c1a7699db4 100644 (file)
@@ -41,7 +41,7 @@ public class ConfigManagerActivator implements BundleActivator {
     private RuntimeGeneratedMappingServiceActivator mappingServiceActivator;
 
     @Override
-    public void start(BundleContext context) throws Exception {
+    public void start(BundleContext context) {
 
         // track bundles containing YangModuleInfo
         ModuleInfoBundleTracker moduleInfoBundleTracker = new ModuleInfoBundleTracker();
@@ -72,7 +72,7 @@ public class ConfigManagerActivator implements BundleActivator {
         try {
             configRegistryJMXRegistrator.registerToJMX(configRegistry);
         } catch (InstanceAlreadyExistsException e) {
-            throw new RuntimeException("Config Registry was already registered to JMX", e);
+            throw new IllegalStateException("Config Registry was already registered to JMX", e);
         }
 
         ServiceTracker<ModuleFactory, Object> serviceTracker = new ServiceTracker<>(context, ModuleFactory.class,
@@ -81,7 +81,7 @@ public class ConfigManagerActivator implements BundleActivator {
     }
 
     @Override
-    public void stop(BundleContext context) throws Exception {
+    public void stop(BundleContext context) {
         try {
             configRegistry.close();
         } catch (Exception e) {
index d6d3893bebdd54113a549bf9692e3851f7545af8..37d5e6bd3fcae0259ae06079d1c909e016b8525f 100644 (file)
@@ -53,7 +53,7 @@ public class FtlFilePersister {
                         ftlFile.getFtlTempleteLocation());
                 try {
                     template.process(ftlFile, writer);
-                } catch (Throwable e) {
+                } catch (Exception e) {
                     throw new IllegalStateException(
                             "Template error while generating " + ftlFile, e);
                 }
index 4a9d5512d3fc024892d641215572b566c51b8d6c..676c8eca6ec6f9a903c34aeebd69d9c8abbeae07 100644 (file)
@@ -195,16 +195,17 @@ final class ModuleMXBeanEntryBuilder {
                 boolean providedServiceWasSet = false;
                 for (UnknownSchemaNode unknownNode : id.getUnknownSchemaNodes()) {
                     // TODO: test this
-                    if (ConfigConstants.PROVIDED_SERVICE_EXTENSION_QNAME.equals(unknownNode.getNodeType())) {
-                        // no op: 0 or more provided identities are allowed
-                    } else if (ConfigConstants.JAVA_NAME_PREFIX_EXTENSION_QNAME.equals(unknownNode.getNodeType())) {
+                    boolean unknownNodeIsProvidedServiceExtension = ConfigConstants.PROVIDED_SERVICE_EXTENSION_QNAME.equals(unknownNode.getNodeType());
+                    // true => no op: 0 or more provided identities are allowed
+
+                    if (ConfigConstants.JAVA_NAME_PREFIX_EXTENSION_QNAME.equals(unknownNode.getNodeType())) {
                         // 0..1 allowed
                         checkState(
                                 providedServiceWasSet == false,
                                 format("More than one language extension %s is not allowed here: %s",
                                         ConfigConstants.JAVA_NAME_PREFIX_EXTENSION_QNAME, id));
                         providedServiceWasSet = true;
-                    } else {
+                    } else if (unknownNodeIsProvidedServiceExtension == false) {
                         throw new IllegalStateException("Unexpected language extension " + unknownNode.getNodeType());
                     }
                 }
index 84300cb81d1000571e5fb52070ebefa91c3c33e4..cbeb5c3b297415bacf1a74596abbbf8d4fb9d207 100644 (file)
@@ -25,7 +25,9 @@ import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import javax.management.openmbean.CompositeType;
 import javax.management.openmbean.OpenDataException;
 import javax.management.openmbean.OpenType;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
@@ -208,22 +210,20 @@ public class TOAttribute extends AbstractAttribute implements TypedAttribute {
 
     @Override
     public CompositeType getOpenType() {
-        String description = getNullableDescription() == null ? getAttributeYangName()
-                : getNullableDescription();
-        final String[] itemNames = new String[yangNameToAttributeMap.keySet()
-                .size()];
-        String[] itemDescriptions = itemNames;
-        FunctionImpl functionImpl = new FunctionImpl(itemNames);
+        String description = getNullableDescription() == null ? getAttributeYangName() : getNullableDescription();
+
+        FunctionImpl functionImpl = new FunctionImpl();
         Map<String, AttributeIfc> jmxPropertiesToTypesMap = getJmxPropertiesToTypesMap();
         OpenType<?>[] itemTypes = Collections2.transform(
                 jmxPropertiesToTypesMap.entrySet(), functionImpl).toArray(
                 new OpenType<?>[] {});
+        String[] itemNames = functionImpl.getItemNames();
         try {
             // TODO add package name to create fully qualified name for this
             // type
             CompositeType compositeType = new CompositeType(
                     getUpperCaseCammelCase(), description, itemNames,
-                    itemDescriptions, itemTypes);
+                    itemNames, itemTypes);
             return compositeType;
         } catch (OpenDataException e) {
             throw new RuntimeException("Unable to create CompositeType for "
@@ -235,20 +235,20 @@ public class TOAttribute extends AbstractAttribute implements TypedAttribute {
         return packageName;
     }
 
-    private static final class FunctionImpl implements
-            Function<Entry<String, AttributeIfc>, OpenType<?>> {
-        private final String[] itemNames;
-        int i = 0;
+}
 
-        private FunctionImpl(String[] itemNames) {
-            this.itemNames = itemNames;
-        }
+class FunctionImpl implements
+        Function<Entry<String, AttributeIfc>, OpenType<?>> {
+    private final List<String> itemNames = new ArrayList<>();
 
-        @Override
-        public OpenType<?> apply(Entry<String, AttributeIfc> input) {
-            AttributeIfc innerType = input.getValue();
-            itemNames[i++] = input.getKey();
-            return innerType.getOpenType();
-        }
+    @Override
+    public OpenType<?> apply(Entry<String, AttributeIfc> input) {
+        AttributeIfc innerType = input.getValue();
+        itemNames.add(input.getKey());
+        return innerType.getOpenType();
+    }
+
+    public String[] getItemNames(){
+        return itemNames.toArray(new String[itemNames.size()]);
     }
 }