Do not allow wildcards in Action.invoke() 78/99678/3
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 10 Feb 2022 09:32:22 +0000 (10:32 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 10 Feb 2022 10:43:08 +0000 (11:43 +0100)
Wildcard invocations do not make sense, as they could match any number
of instances. Document such attempts as throwing IAE.

Change-Id: I23780fee31c2f6c60d883764c046703ee92687f2
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/ActionAdapter.java
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/Action.java

index e8d9e95eaf6654ded084d097134bbd1242f8260c..04bdbd8050231289095b66b2a4a5005c1e3ff0e7 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.mdsal.binding.dom.adapter;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 import static org.opendaylight.mdsal.binding.dom.adapter.StaticConfiguration.ENABLE_CODEC_SHORTCUT;
 import static org.opendaylight.yangtools.yang.common.YangConstants.operationInputQName;
@@ -60,6 +61,8 @@ final class ActionAdapter extends AbstractBindingAdapter<DOMActionService> imple
             case "invoke":
                 if (args.length == 2) {
                     final InstanceIdentifier<?> path = (InstanceIdentifier<?>) requireNonNull(args[0]);
+                    checkArgument(!path.isWildcarded(), "Cannot invoke action on wildcard path %s", path);
+
                     final RpcInput input = (RpcInput) requireNonNull(args[1]);
                     final CurrentAdapterSerializer serializer = currentSerializer();
                     final ListenableFuture<? extends DOMActionResult> future = getDelegate().invokeAction(actionPath,
index 4950c085a0195359596b48e9eb605afe23029716..7e809b4d08e349b0933b32e91e2ec896bd5268aa 100644 (file)
@@ -28,6 +28,7 @@ public interface Action<P extends InstanceIdentifier<?>, I extends RpcInput, O e
      * @param input Input argument
      * @return Future result of invocation
      * @throws NullPointerException if any of the arguments are null
+     * @throws IllegalArgumentException if {@code path} is {@link InstanceIdentifier#isWildcarded()}
      */
     @CheckReturnValue
     @NonNull ListenableFuture<@NonNull RpcResult<@NonNull O>> invoke(@NonNull P path, @NonNull I input);