Correct InstanceIdentifier.trustedCreate()
[mdsal.git] / binding / yang-binding / src / main / java / org / opendaylight / yangtools / yang / binding / InstanceIdentifier.java
index 48b199d678bd0280bb8a6613d0b6445d248ae6ae..2e26148960f180fd7d4bf93ff8f750701ddf17ec 100644 (file)
@@ -623,19 +623,14 @@ public class InstanceIdentifier<T extends DataObject>
 
     @SuppressWarnings({ "unchecked", "rawtypes" })
     static <N extends DataObject> @NonNull InstanceIdentifier<N> trustedCreate(final PathArgument arg,
-            final Iterable<PathArgument> pathArguments, final int hash, boolean wildcarded) {
-        if (Identifiable.class.isAssignableFrom(arg.getType()) && !wildcarded) {
-            Identifier<?> key = null;
-            if (arg instanceof IdentifiableItem) {
-                key = ((IdentifiableItem<?, ?>)arg).getKey();
-            } else {
-                wildcarded = true;
-            }
-
-            return new KeyedInstanceIdentifier(arg.getType(), pathArguments, wildcarded, hash, key);
+            final Iterable<PathArgument> pathArguments, final int hash, final boolean wildcarded) {
+        if (arg instanceof IdentifiableItem<?, ?> identifiable) {
+            return new KeyedInstanceIdentifier(arg.getType(), pathArguments, wildcarded, hash, identifiable.getKey());
         }
 
-        return new InstanceIdentifier(arg.getType(), pathArguments, wildcarded, hash);
+        final var type = arg.getType();
+        return new InstanceIdentifier(type, pathArguments, wildcarded || Identifiable.class.isAssignableFrom(type),
+            hash);
     }
 
     /**