<artifactId>spotbugs-annotations</artifactId>
<optional>true</optional>
</dependency>
+ <dependency>
+ <groupId>org.eclipse.jdt</groupId>
+ <artifactId>org.eclipse.jdt.annotation</artifactId>
+ </dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>concepts</artifactId>
--- /dev/null
+/*
+ * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.common;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+
+/**
+ * Utility methods to hide operations that incur SpotBugs wrath used by public classes where we do not want to leak
+ * {@link SuppressFBWarnings}.
+ */
+final class DoNotLeakSpotbugs {
+ private DoNotLeakSpotbugs() {
+ // Hidden on purpose
+ }
+
+ @SuppressFBWarnings(value = "ES_COMPARING_PARAMETER_STRING_WITH_EQ", justification = "Interning identity check")
+ static @Nullable String internedString(final @NonNull String str) {
+ final var interned = str.intern();
+ return interned == str ? null : interned;
+ }
+}
import com.google.common.base.MoreObjects;
import com.google.common.collect.Interner;
import com.google.common.collect.Interners;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
}
@Override
- @SuppressFBWarnings(value = "ES_COMPARING_STRINGS_WITH_EQ", justification = "Interning identity check")
public Qualified intern() {
// Make sure to intern the string and check whether it refers to the same name as we are
- final String name = getLocalName();
- final String internedName = name.intern();
- final Qualified template = internedName == name ? this : new Qualified(prefix.intern(), internedName);
+ final String internedName = DoNotLeakSpotbugs.internedString(getLocalName());
+ final Qualified template = internedName == null ? this : new Qualified(prefix.intern(), internedName);
return INTERNER.intern(template);
}
}
@Override
- @SuppressFBWarnings(value = "ES_COMPARING_STRINGS_WITH_EQ", justification = "Interning identity check")
public Unqualified intern() {
// Make sure to intern the string and check whether it refers to the same name as we are
- final String name = getLocalName();
- final String internedName = name.intern();
- final Unqualified template = internedName == name ? this : new Unqualified(internedName);
+ final var internedName = DoNotLeakSpotbugs.internedString(getLocalName());
+ final var template = internedName == null ? this : new Unqualified(internedName);
return INTERNER.intern(template);
}