We are getting confused between immediate throws and returns. The
exception factory methods should be returning the exception and not
throwing it.
Fix this up and add a SpotBugs annotation so that throws are guarded.
Also mark IncorrectNestingException for evolution. Final improvement
that we now have a completely-static factory method.
Change-Id: I5262c0dbb31d6935f258909828aac5331c70801b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit
469a57c3adac4b6ae0df0c6398d926096cca13e2)
import com.google.common.annotations.Beta;
import java.io.Serial;
import com.google.common.annotations.Beta;
import java.io.Serial;
+import org.eclipse.jdt.annotation.NonNull;
/**
* Thrown where incorrect nesting of data structures was detected and was caused by user. This typically indicates
/**
* Thrown where incorrect nesting of data structures was detected and was caused by user. This typically indicates
- public static IncorrectNestingException create(final String message, final Object... args) {
- return new IncorrectNestingException(String.format(message, args));
+ public IncorrectNestingException(final String message, final Object... args) {
+ this(message.formatted(args));
+ }
+
+ @Deprecated(since = "12.0.0", forRemoval = true)
+ public static @NonNull IncorrectNestingException create(final String message, final Object... args) {
+ return new IncorrectNestingException(message, args);
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableSet;
+import edu.umd.cs.findbugs.annotations.CheckReturnValue;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
private IllegalArgumentException childNullException(final QName child, final String message, final Object... args) {
final QNameModule module = child.getModule();
if (!factory().getRuntimeContext().getEffectiveModelContext().findModule(module).isPresent()) {
private IllegalArgumentException childNullException(final QName child, final String message, final Object... args) {
final QNameModule module = child.getModule();
if (!factory().getRuntimeContext().getEffectiveModelContext().findModule(module).isPresent()) {
- throw new MissingSchemaException("Module " + module + " is not present in current schema context.");
+ return new MissingSchemaException("Module " + module + " is not present in current schema context.");
- throw IncorrectNestingException.create(message, args);
+ return new IncorrectNestingException(message, args);
- private IllegalArgumentException childNullException(final Class<?> childClass, final String message,
+ @CheckReturnValue
+ private @NonNull IllegalArgumentException childNullException(final Class<?> childClass, final String message,
- final BindingRuntimeContext runtimeContext = factory().getRuntimeContext();
+ return childNullException(factory().getRuntimeContext(), childClass, message, args);
+ }
+
+ @CheckReturnValue
+ private static @NonNull IllegalArgumentException childNullException(final BindingRuntimeContext runtimeContext,
+ final Class<?> childClass, final String message, final Object... args) {
final CompositeRuntimeType schema;
if (Augmentation.class.isAssignableFrom(childClass)) {
schema = runtimeContext.getAugmentationDefinition(childClass.asSubclass(Augmentation.class));
final CompositeRuntimeType schema;
if (Augmentation.class.isAssignableFrom(childClass)) {
schema = runtimeContext.getAugmentationDefinition(childClass.asSubclass(Augmentation.class));
schema = runtimeContext.getSchemaDefinition(childClass);
}
if (schema == null) {
schema = runtimeContext.getSchemaDefinition(childClass);
}
if (schema == null) {
- throw new MissingSchemaForClassException(childClass);
+ return new MissingSchemaForClassException(childClass);
}
try {
runtimeContext.loadClass(Type.of(childClass));
} catch (final ClassNotFoundException e) {
}
try {
runtimeContext.loadClass(Type.of(childClass));
} catch (final ClassNotFoundException e) {
- throw new MissingClassInLoadingStrategyException(
+ return new MissingClassInLoadingStrategyException(
"User supplied class " + childClass.getName() + " is not available in " + runtimeContext, e);
}
"User supplied class " + childClass.getName() + " is not available in " + runtimeContext, e);
}
- throw IncorrectNestingException.create(message, args);
+ return new IncorrectNestingException(message, args);
}
private static QName extractName(final YangInstanceIdentifier.PathArgument child) {
}
private static QName extractName(final YangInstanceIdentifier.PathArgument child) {