This method is for things like binding/dom codec and similar users who
know what they are doing. Rename the method to 'unsafeOf()', so that the
compilation failures from the change in InstanceIdentifier.create(Class)'s
signature do not produce confusing guidance by pointing to this arcane
method.
Also document this method's purpose, with significant warning and update
it to take a List.
JIRA: MDSAL-730
Change-Id: I9def3750f16d87c11d12809e0f067daf0bf352b9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
}
final DataObject lazyObj = codec.deserialize(data);
}
final DataObject lazyObj = codec.deserialize(data);
- final InstanceIdentifier<?> bindingPath = InstanceIdentifier.create(builder);
+ final InstanceIdentifier<?> bindingPath = InstanceIdentifier.unsafeOf(builder);
return Map.entry(bindingPath, lazyObj);
}
return Map.entry(bindingPath, lazyObj);
}
// which is not binding representable.
return null;
}
// which is not binding representable.
return null;
}
- @SuppressWarnings("unchecked")
- final InstanceIdentifier<T> ret = (InstanceIdentifier<T>) InstanceIdentifier.create(builder);
- return ret;
+
+ return InstanceIdentifier.unsafeOf(builder);
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.base.VerifyException;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.base.VerifyException;
-import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.Collections;
import java.util.Iterator;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.Collections;
import java.util.Iterator;
import java.util.Objects;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import java.util.Objects;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
- * Create an instance identifier for a very specific object type.
+ * Create an instance identifier for a sequence of {@link PathArgument} steps. The steps are required to be formed
+ * of classes extending either {@link ChildOf} or {@link Augmentation} contracts. This method does not check whether
+ * or not the sequence is structurally sound, for example that an {@link Augmentation} follows an
+ * {@link Augmentable} step. Furthermore the compile-time indicated generic type of the returned object does not
+ * necessarily match the contained state.
- * Example:
- * <pre>
- * List<PathArgument> path = Arrays.asList(new Item(Nodes.class))
- * new InstanceIdentifier(path);
- * </pre>
+ * Failure to observe precautions to validate the list's contents may yield an object which mey be rejected at
+ * run-time or lead to undefined behaviour.
*
* @param pathArguments The path to a specific node in the data tree
* @return InstanceIdentifier instance
*
* @param pathArguments The path to a specific node in the data tree
* @return InstanceIdentifier instance
- * @throws IllegalArgumentException if pathArguments is empty or
- * contains a null element.
+ * @throws NullPointerException if {@code pathArguments} is, or contains an item which is, {@code null}
+ * @throws IllegalArgumentException if {@code pathArguments} is empty or contains an item which does not represent
+ * a valid addressing step.
- // FIXME: rename to 'unsafeOf()'
- public static @NonNull InstanceIdentifier<?> create(final Iterable<? extends PathArgument> pathArguments) {
- if (pathArguments instanceof ImmutableCollection) {
- @SuppressWarnings("unchecked")
- final var immutableArguments = (ImmutableCollection<PathArgument>) pathArguments;
- return internalCreate(immutableArguments);
- }
-
- return internalCreate(ImmutableList.copyOf(pathArguments));
+ @SuppressWarnings("unchecked")
+ public static <T extends DataObject> @NonNull InstanceIdentifier<T> unsafeOf(
+ final List<? extends PathArgument> pathArguments) {
+ return (InstanceIdentifier<T>) internalCreate(ImmutableList.copyOf(pathArguments));
Whitebox.setInternalState(instanceIdentifier5, "hash", instanceIdentifier1.hashCode());
Whitebox.setInternalState(instanceIdentifier5, "wildcarded", false);
Whitebox.setInternalState(instanceIdentifier5, "hash", instanceIdentifier1.hashCode());
Whitebox.setInternalState(instanceIdentifier5, "wildcarded", false);
- assertNotNull(InstanceIdentifier.create(ImmutableList.copyOf(instanceIdentifier1.getPathArguments())));
+ assertNotNull(InstanceIdentifier.unsafeOf(ImmutableList.copyOf(instanceIdentifier1.getPathArguments())));
assertNotNull(InstanceIdentifier.create(Nodes.class).child(Node.class));
assertNotNull(InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(5)));
assertNotNull(instanceIdentifier5.augmentation(NodeAugmentation.class));
assertNotNull(InstanceIdentifier.create(Nodes.class).child(Node.class));
assertNotNull(InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(5)));
assertNotNull(instanceIdentifier5.augmentation(NodeAugmentation.class));