X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=binding%2Fmdsal-binding-generator%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fgenerator%2Fimpl%2Frt%2FAbstractCompositeRuntimeType.java;h=d144120299330e2f4f01cf91949ac064cb01f57b;hb=edc1fe4610c43c79a039ce8156c143a5ee43df89;hp=a806f99a484f4721fd1b2e2c9408c1facb60694b;hpb=f052b186f3f1c7c314ab71a8cd0b4df4c00fda1e;p=mdsal.git diff --git a/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/rt/AbstractCompositeRuntimeType.java b/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/rt/AbstractCompositeRuntimeType.java index a806f99a48..d144120299 100644 --- a/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/rt/AbstractCompositeRuntimeType.java +++ b/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/rt/AbstractCompositeRuntimeType.java @@ -7,13 +7,12 @@ */ package org.opendaylight.mdsal.binding.generator.impl.rt; -import static com.google.common.base.Verify.verify; import static java.util.Objects.requireNonNull; +import static java.util.Objects.requireNonNullElse; import com.google.common.base.Functions; import com.google.common.base.VerifyException; import com.google.common.collect.ImmutableMap; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -34,8 +33,6 @@ abstract class AbstractCompositeRuntimeType> private final ImmutableMap byClass; private final Object bySchemaTree; - @SuppressFBWarnings(value = "SE_COMPARATOR_SHOULD_BE_SERIALIZABLE", - justification = "https://github.com/spotbugs/spotbugs/issues/1985") AbstractCompositeRuntimeType(final GeneratedType bindingType, final S statement, final List children) { super(bindingType, statement); @@ -53,7 +50,9 @@ abstract class AbstractCompositeRuntimeType> default -> { Arrays.sort(tmp, (o1, o2) -> { final int cmp = extractQName(o1).compareTo(extractQName(o2)); - verify(cmp != 0, "Type %s conflicts with %s on schema tree", o1, o2); + if (cmp == 0) { + throw new VerifyException("Type " + o1 + " conflicts with " + o2 + " on schema tree"); + } return cmp; }); yield tmp; @@ -68,15 +67,13 @@ abstract class AbstractCompositeRuntimeType> } final var tmp = (RuntimeType[]) bySchemaTree; - @SuppressFBWarnings(value = "SE_COMPARATOR_SHOULD_BE_SERIALIZABLE", - justification = "https://github.com/spotbugs/spotbugs/issues/1985") - final int offset = Arrays.binarySearch(tmp, null, (o1, o2) -> { - // We make assumptions about how Arrays.binarySearch() is implemented: o2 is expected to be the provided - // key -- which is null. This helps CHA by not introducing a fake RuntimeType class and the - // corresponding instanceof checks. - verify(o2 == null, "Unexpected key %s", o2); - return extractQName(o1).compareTo(qname); - }); + // Here we are assuming that Arrays.binarySearch() accepts a null object, so as to help CHA by not introducing + // a fake RuntimeType class and the corresponding instanceof checks to side-step the statement lookup (which + // would need more faking). + // We make a slight assumption that o2 is the what we specify as a key, but can recover if it is the other way + // around. + final int offset = Arrays.binarySearch(tmp, null, + (o1, o2) -> extractQName(requireNonNullElse(o1, o2)).compareTo(qname)); return offset < 0 ? null : tmp[offset]; } @@ -94,7 +91,9 @@ abstract class AbstractCompositeRuntimeType> final var tmp = (RuntimeType[]) bySchemaTree; for (var item : tmp) { - verify(expectedType.isInstance(item), "Unexpected schema tree child %s", item); + if (!expectedType.isInstance(item)) { + throw new VerifyException("Unexpected schema tree child " + item); + } } return (List) Collections.unmodifiableList(Arrays.asList(tmp)); }