Do not retain java.lang.reflect.Method in ValueNodeCodecContext
[mdsal.git] / binding / mdsal-binding-dom-codec / src / main / java / org / opendaylight / mdsal / binding / dom / codec / impl / SchemaRootCodecContext.java
index 095d5e94ba406abef7c93c58aa49d632dd894dee..c8200d2ba7fef8a587a6531b52352e521c2adcb7 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.mdsal.binding.dom.codec.impl;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.base.Verify.verify;
 
 import com.google.common.base.Throwables;
@@ -219,8 +219,10 @@ final class SchemaRootCodecContext<D extends DataObject> extends DataContainerCo
 
     private ActionCodecContext prepareActionContext(final int inputOffset, final int outputOffset,
             final int expectedArgsLength, final Class<? extends Action<?, ?, ?>> action, final Class<?> actionType) {
-        final ParameterizedType paramType = checkNotNull(ClassLoaderUtils.findParameterizedType(action, actionType),
-            "There does not exist any ParameterType in %s", action);
+        final Optional<ParameterizedType> optParamType = ClassLoaderUtils.findParameterizedType(action, actionType);
+        checkState(optParamType.isPresent(), "%s does not specialize %s", action, actionType);
+
+        final ParameterizedType paramType = optParamType.get();
         final Type[] args = paramType.getActualTypeArguments();
         checkArgument(args.length == expectedArgsLength, "Unexpected (%s) Action generatic arguments", args.length);
         final ActionDefinition schema = factory().getRuntimeContext().getActionDefinition(action);
@@ -244,27 +246,22 @@ final class SchemaRootCodecContext<D extends DataObject> extends DataContainerCo
                 .orElseThrow(() -> new IllegalArgumentException("Failed to find module for " + qnameModule));
         final String className = BindingMapping.getClassName(qname);
 
-        RpcDefinition rpc = null;
         for (final RpcDefinition potential : module.getRpcs()) {
             final QName potentialQName = potential.getQName();
             /*
-             * Check if rpc and class represents data from same module and then
-             * checks if rpc local name produces same class name as class name
-             * appended with Input/Output based on QName associated with bidning
-             * class.
+             * Check if rpc and class represents data from same module and then checks if rpc local name produces same
+             * class name as class name appended with Input/Output based on QName associated with binding class.
              *
-             * FIXME: Rework this to have more precise logic regarding Binding
-             * Specification.
+             * FIXME: Rework this to have more precise logic regarding Binding Specification.
              */
             if (key.getSimpleName().equals(BindingMapping.getClassName(potentialQName) + className)) {
-                rpc = potential;
-                break;
+                final ContainerSchemaNode schema = SchemaNodeUtils.getRpcDataSchema(potential, qname);
+                checkArgument(schema != null, "Schema for %s does not define input / output.", potential.getQName());
+                return (ContainerNodeCodecContext<?>) DataContainerCodecPrototype.from(key, schema, factory()).get();
             }
         }
-        checkArgument(rpc != null, "Supplied class %s is not valid RPC class.", key);
-        final ContainerSchemaNode schema = SchemaNodeUtils.getRpcDataSchema(rpc, qname);
-        checkArgument(schema != null, "Schema for %s does not define input / output.", rpc.getQName());
-        return (ContainerNodeCodecContext<?>) DataContainerCodecPrototype.from(key, schema, factory()).get();
+
+        throw new IllegalArgumentException("Supplied class " + key + " is not valid RPC class.");
     }
 
     NotificationCodecContext<?> createNotificationDataContext(final Class<?> notificationType) {