Migrate common/util to use JDT annotations 12/76712/7
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 5 Oct 2018 09:02:56 +0000 (11:02 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 8 Oct 2018 23:18:56 +0000 (01:18 +0200)
This removes run-time reliance on javax.annotation package.

Change-Id: I59193dbe7fcf472fbab29099b685df669c3b301a
JIRA: YANGTOOLS-907
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
25 files changed:
common/util/src/main/java/org/opendaylight/yangtools/util/AbstractIdentifier.java
common/util/src/main/java/org/opendaylight/yangtools/util/AbstractStringIdentifier.java
common/util/src/main/java/org/opendaylight/yangtools/util/AbstractUUIDIdentifier.java
common/util/src/main/java/org/opendaylight/yangtools/util/ConstantArrayCollection.java
common/util/src/main/java/org/opendaylight/yangtools/util/ExecutorServiceUtil.java
common/util/src/main/java/org/opendaylight/yangtools/util/ImmutableOffsetMap.java
common/util/src/main/java/org/opendaylight/yangtools/util/ModifiableMapPhase.java
common/util/src/main/java/org/opendaylight/yangtools/util/MutableOffsetMap.java
common/util/src/main/java/org/opendaylight/yangtools/util/ObjectRegistry.java
common/util/src/main/java/org/opendaylight/yangtools/util/OffsetMapCache.java
common/util/src/main/java/org/opendaylight/yangtools/util/OptionalBoolean.java
common/util/src/main/java/org/opendaylight/yangtools/util/ReadWriteTrieMap.java
common/util/src/main/java/org/opendaylight/yangtools/util/RecursiveObjectLeaker.java
common/util/src/main/java/org/opendaylight/yangtools/util/SharedSingletonMap.java
common/util/src/main/java/org/opendaylight/yangtools/util/SingletonSet.java
common/util/src/main/java/org/opendaylight/yangtools/util/UnmodifiableCollection.java
common/util/src/main/java/org/opendaylight/yangtools/util/UnmodifiableMapPhase.java
common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListenableFutureTask.java
common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListeningExecutorService.java
common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/DeadlockDetectingListeningExecutorService.java
common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManager.java
common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/TrackingLinkedBlockingQueue.java
common/util/src/main/java/org/opendaylight/yangtools/util/xml/UntrustedXML.java
common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListeningExecutorServiceTest.java
common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/DeadlockDetectingListeningExecutorServiceTest.java

index 57b53dc43647572ecb950af90fbba4deafa5e891..408afcb976ffefd8859e0e1d45f6c2dee80d415b 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.yangtools.util;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.base.MoreObjects;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.Identifier;
 
 /**
@@ -23,13 +24,13 @@ import org.opendaylight.yangtools.concepts.Identifier;
 public abstract class AbstractIdentifier<T> implements Identifier {
     private static final long serialVersionUID = 1L;
 
-    private final T value;
+    private final @NonNull T value;
 
-    public AbstractIdentifier(final T value) {
+    public AbstractIdentifier(final @NonNull T value) {
         this.value = requireNonNull(value);
     }
 
-    public final T getValue() {
+    public final @NonNull T getValue() {
         return value;
     }
 
@@ -51,7 +52,7 @@ public abstract class AbstractIdentifier<T> implements Identifier {
     }
 
     @Override
-    public final String toString() {
+    public final @NonNull String toString() {
         return MoreObjects.toStringHelper(this).add("value", value).toString();
     }
 }
index 3d1cd4d057d73864ff86582f79dcae576a601540..18f9ddc870bf024144950a7b9907dafa11d18e8d 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.yangtools.util;
 
 import com.google.common.annotations.Beta;
 import java.util.UUID;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.Identifier;
 
 /**
@@ -22,13 +22,13 @@ public abstract class AbstractStringIdentifier<T extends AbstractStringIdentifie
         extends AbstractIdentifier<String> implements Comparable<T> {
     private static final long serialVersionUID = 1L;
 
-    protected AbstractStringIdentifier(final String string) {
+    protected AbstractStringIdentifier(final @NonNull String string) {
         super(string);
     }
 
     @Override
     @SuppressWarnings("checkstyle:parameterName")
-    public final int compareTo(@Nonnull final T o) {
+    public final int compareTo(final T o) {
         return getValue().compareTo(o.getValue());
     }
 }
index 6043eee29c95fd0f62aee34b88644ce018e33183..3251004f753c9f6a79d2e46da8bd29d36c46d18f 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.yangtools.util;
 
 import com.google.common.annotations.Beta;
 import java.util.UUID;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.Identifier;
 
 /**
@@ -22,13 +22,13 @@ public abstract class AbstractUUIDIdentifier<T extends AbstractUUIDIdentifier<T>
         implements Comparable<T> {
     private static final long serialVersionUID = 1L;
 
-    protected AbstractUUIDIdentifier(final UUID uuid) {
+    protected AbstractUUIDIdentifier(final @NonNull UUID uuid) {
         super(uuid);
     }
 
     @Override
     @SuppressWarnings("checkstyle:parameterName")
-    public final int compareTo(@Nonnull final T o) {
+    public final int compareTo(final T o) {
         return getValue().compareTo(o.getValue());
     }
 }
index 1dcfaa2a568b9df60ce4cd07ab966fb8c71428ec..ed84c62d93266bb67715bb48b18d87f8f7616d99 100644 (file)
@@ -16,7 +16,7 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.NoSuchElementException;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
 
 /**
  * Internal array-backed {@link List}. It assumes the array does not contain nulls and it does not get modified
@@ -27,9 +27,9 @@ import javax.annotation.Nonnull;
  */
 final class ConstantArrayCollection<E> implements Collection<E>, Serializable {
     private static final long serialVersionUID = 1L;
-    private final E[] array;
+    private final E @NonNull[] array;
 
-    ConstantArrayCollection(final E[] array) {
+    ConstantArrayCollection(final E @NonNull[] array) {
         this.array = requireNonNull(array);
     }
 
@@ -54,9 +54,8 @@ final class ConstantArrayCollection<E> implements Collection<E>, Serializable {
         return false;
     }
 
-    @Nonnull
     @Override
-    public Iterator<E> iterator() {
+    public @NonNull Iterator<E> iterator() {
         return new UnmodifiableIterator<E>() {
             private int offset = 0;
 
@@ -75,16 +74,14 @@ final class ConstantArrayCollection<E> implements Collection<E>, Serializable {
         };
     }
 
-    @Nonnull
     @Override
-    public Object[] toArray() {
+    public @NonNull Object[] toArray() {
         return array.clone();
     }
 
-    @Nonnull
     @SuppressWarnings({ "unchecked", "checkstyle:parameterName" })
     @Override
-    public <T> T[] toArray(@Nonnull final T[] a) {
+    public <T> T[] toArray(final T[] a) {
         if (a.length < array.length) {
             return Arrays.copyOf(array, array.length, (Class<T[]>)a.getClass().getComponentType());
         }
@@ -110,7 +107,7 @@ final class ConstantArrayCollection<E> implements Collection<E>, Serializable {
 
     @Override
     @SuppressWarnings("checkstyle:parameterName")
-    public boolean containsAll(@Nonnull final Collection<?> c) {
+    public boolean containsAll(final Collection<?> c) {
         for (Object o : c) {
             if (!contains(o)) {
                 return false;
@@ -122,19 +119,19 @@ final class ConstantArrayCollection<E> implements Collection<E>, Serializable {
 
     @Override
     @SuppressWarnings("checkstyle:parameterName")
-    public boolean addAll(@Nonnull final Collection<? extends E> c) {
+    public boolean addAll(final Collection<? extends E> c) {
         throw new UnsupportedOperationException();
     }
 
     @Override
     @SuppressWarnings("checkstyle:parameterName")
-    public boolean removeAll(@Nonnull final Collection<?> c) {
+    public boolean removeAll(final Collection<?> c) {
         throw new UnsupportedOperationException();
     }
 
     @Override
     @SuppressWarnings("checkstyle:parameterName")
-    public boolean retainAll(@Nonnull final Collection<?> c) {
+    public boolean retainAll(final Collection<?> c) {
         throw new UnsupportedOperationException();
     }
 
@@ -165,7 +162,7 @@ final class ConstantArrayCollection<E> implements Collection<E>, Serializable {
     }
 
     @Override
-    public String toString() {
+    public @NonNull String toString() {
         if (array.length == 0) {
             return "[]";
         }
index da1a5255ae27b0f584983c30ce71f515de96d44a..b438a96215268d8ab4c2fb8af91b74a47b1f8302 100644 (file)
@@ -14,7 +14,7 @@ import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.RejectedExecutionHandler;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -40,7 +40,7 @@ public final class ExecutorServiceUtil {
     }
 
     private static final Logger LOG = LoggerFactory.getLogger(ExecutorServiceUtil.class);
-    private static final RejectedExecutionHandler WAIT_IN_QUEUE_HANDLER = new WaitInQueueExecutionHandler();
+    private static final @NonNull RejectedExecutionHandler WAIT_IN_QUEUE_HANDLER = new WaitInQueueExecutionHandler();
 
     private ExecutorServiceUtil() {
         throw new UnsupportedOperationException("Utility class");
@@ -55,11 +55,11 @@ public final class ExecutorServiceUtil {
      * @param delegate Backing blocking queue.
      * @return A new blocking queue backed by the delegate
      */
-    public static <E> BlockingQueue<E> offerFailingBlockingQueue(final BlockingQueue<E> delegate) {
+    public static <E> @NonNull BlockingQueue<E> offerFailingBlockingQueue(final BlockingQueue<E> delegate) {
         return new ForwardingBlockingQueue<E>() {
             @Override
             @SuppressWarnings("checkstyle:parameterName")
-            public boolean offer(@Nonnull final E o) {
+            public boolean offer(final E o) {
                 return false;
             }
 
@@ -76,7 +76,7 @@ public final class ExecutorServiceUtil {
      *
      * @return A shared RejectedExecutionHandler instance.
      */
-    public static RejectedExecutionHandler waitInQueueExecutionHandler() {
+    public static @NonNull RejectedExecutionHandler waitInQueueExecutionHandler() {
         return WAIT_IN_QUEUE_HANDLER;
     }
 
@@ -85,8 +85,8 @@ public final class ExecutorServiceUtil {
      * timeout period. If the timeout elapses before termination, the executor is forcefully
      * shutdown.
      */
-    public static void tryGracefulShutdown(final ExecutorService executor, final long timeout, final TimeUnit unit) {
-
+    public static void tryGracefulShutdown(final @NonNull ExecutorService executor, final long timeout,
+            final @NonNull TimeUnit unit) {
         executor.shutdown();
 
         try {
index e899a1e60e695f022253c5d0c00de760839aa9fc..4cadc268cb845466e8220c5b3c18953de2b97d1e 100644 (file)
@@ -27,7 +27,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 
 /**
@@ -43,13 +43,12 @@ public abstract class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K
     static final class Ordered<K, V> extends ImmutableOffsetMap<K, V> {
         private static final long serialVersionUID = 1L;
 
-        Ordered(final Map<K, Integer> offsets, final V[] objects) {
+        Ordered(final @NonNull Map<K, Integer> offsets, final @NonNull V[] objects) {
             super(offsets, objects);
         }
 
-        @Nonnull
         @Override
-        public MutableOffsetMap<K, V> toModifiableMap() {
+        public @NonNull MutableOffsetMap<K, V> toModifiableMap() {
             return MutableOffsetMap.orderedCopyOf(this);
         }
 
@@ -67,9 +66,8 @@ public abstract class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K
             super(offsets, objects);
         }
 
-        @Nonnull
         @Override
-        public MutableOffsetMap<K, V> toModifiableMap() {
+        public @NonNull MutableOffsetMap<K, V> toModifiableMap() {
             return MutableOffsetMap.unorderedCopyOf(this);
         }
 
@@ -84,8 +82,8 @@ public abstract class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K
 
     private static final long serialVersionUID = 1L;
 
-    private final transient Map<K, Integer> offsets;
-    private final transient V[] objects;
+    private final transient @NonNull Map<K, Integer> offsets;
+    private final transient @NonNull V[] objects;
     private transient int hashCode;
 
     /**
@@ -95,15 +93,14 @@ public abstract class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K
      * @param objects Array of value object, may not be null. The array is stored as is, the caller
      *              is responsible for ensuring its contents remain unmodified.
      */
-    ImmutableOffsetMap(@Nonnull final Map<K, Integer> offsets, @Nonnull final V[] objects) {
+    ImmutableOffsetMap(final @NonNull Map<K, Integer> offsets, final @NonNull V[] objects) {
         this.offsets = requireNonNull(offsets);
         this.objects = requireNonNull(objects);
         checkArgument(offsets.size() == objects.length);
     }
 
-    @Nonnull
     @Override
-    public abstract MutableOffsetMap<K, V> toModifiableMap();
+    public abstract @NonNull MutableOffsetMap<K, V> toModifiableMap();
 
     abstract void setFields(List<K> keys, V[] values) throws IOException;
 
@@ -122,7 +119,7 @@ public abstract class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K
      *            Input map, may not be null.
      * @return An isolated, immutable copy of the input map
      */
-    @Nonnull public static <K, V> Map<K, V> orderedCopyOf(@Nonnull final Map<K, V> map) {
+    public static <K, V> @NonNull Map<K, V> orderedCopyOf(final @NonNull Map<K, V> map) {
         final Map<K, V> common = commonCopy(map);
         if (common != null) {
             return common;
@@ -160,7 +157,7 @@ public abstract class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K
      *            Input map, may not be null.
      * @return An isolated, immutable copy of the input map
      */
-    @Nonnull public static <K, V> Map<K, V> unorderedCopyOf(@Nonnull final Map<K, V> map) {
+    public static <K, V> @NonNull Map<K, V> unorderedCopyOf(final @NonNull Map<K, V> map) {
         final Map<K, V> common = commonCopy(map);
         if (common != null) {
             return common;
@@ -183,7 +180,7 @@ public abstract class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K
         return new Unordered<>(offsets, array);
     }
 
-    private static <K, V> @Nullable Map<K, V> commonCopy(@Nonnull final Map<K, V> map) {
+    private static <K, V> @Nullable Map<K, V> commonCopy(final @NonNull Map<K, V> map) {
         // Prevent a copy. Note that ImmutableMap is not listed here because of its potentially larger keySet overhead.
         if (map instanceof ImmutableOffsetMap || map instanceof SharedSingletonMap) {
             return map;
@@ -303,7 +300,7 @@ public abstract class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K
 
     @Override
     @SuppressWarnings("checkstyle:parameterName")
-    public final void putAll(@Nonnull final Map<? extends K, ? extends V> m) {
+    public final void putAll(final Map<? extends K, ? extends V> m) {
         throw new UnsupportedOperationException();
     }
 
@@ -317,15 +314,13 @@ public abstract class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K
         return offsets.keySet();
     }
 
-    @Nonnull
     @Override
-    public final Collection<V> values() {
+    public final @NonNull Collection<V> values() {
         return new ConstantArrayCollection<>(objects);
     }
 
-    @Nonnull
     @Override
-    public final Set<Entry<K, V>> entrySet() {
+    public final @NonNull Set<Entry<K, V>> entrySet() {
         return new EntrySet();
     }
 
@@ -347,20 +342,18 @@ public abstract class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K
         return sb.append('}').toString();
     }
 
-    final Map<K, Integer> offsets() {
+    final @NonNull Map<K, Integer> offsets() {
         return offsets;
     }
 
-    final V[] objects() {
+    final @NonNull V[] objects() {
         return objects;
     }
 
     private final class EntrySet extends AbstractSet<Entry<K, V>> {
-        @Nonnull
         @Override
-        public Iterator<Entry<K, V>> iterator() {
+        public @NonNull Iterator<Entry<K, V>> iterator() {
             final Iterator<Entry<K, Integer>> it = offsets.entrySet().iterator();
-
             return new UnmodifiableIterator<Entry<K, V>>() {
                 @Override
                 public boolean hasNext() {
@@ -392,7 +385,7 @@ public abstract class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K
     private static final Field OFFSETS_FIELD = fieldFor("offsets");
     private static final Field ARRAY_FIELD = fieldFor("objects");
 
-    private static Field fieldFor(final String name) {
+    private static @NonNull Field fieldFor(final @NonNull String name) {
         final Field f;
         try {
             f = ImmutableOffsetMap.class.getDeclaredField(name);
@@ -404,8 +397,8 @@ public abstract class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K
         return f;
     }
 
-    private static void setField(final ImmutableOffsetMap<?, ?> map, final Field field, final Object value)
-            throws IOException {
+    private static void setField(final @NonNull ImmutableOffsetMap<?, ?> map, final @NonNull Field field,
+            final Object value) throws IOException {
         try {
             field.set(map, value);
         } catch (IllegalArgumentException | IllegalAccessException e) {
@@ -414,7 +407,7 @@ public abstract class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K
     }
 
     @SuppressWarnings("unchecked")
-    private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
+    private void readObject(final @NonNull ObjectInputStream in) throws IOException, ClassNotFoundException {
         final int s = in.readInt();
 
         final List<K> keys = new ArrayList<>(s);
index dbf3a72010ec61f8e7a0b9d7385e13cb918fdfcd..cd4ba695d5bdbe8daab9b819d20364859dea82b3 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.yangtools.util;
 import com.google.common.annotations.Beta;
 import com.google.common.collect.ImmutableMap;
 import java.util.Map;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.Mutable;
 
 /**
@@ -36,5 +36,5 @@ public interface ModifiableMapPhase<K, V> extends Map<K, V>, Mutable {
      *
      * @return An unmodifiable version of this map.
      */
-    @Nonnull Map<K, V> toUnmodifiableMap();
+    @NonNull Map<K, V> toUnmodifiableMap();
 }
index 09511523bb901bf9abdedc36ca805d5410560eca..299a443d9086d4a142a50486825212caec924970 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.util;
 
+import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.base.Verify.verify;
 import static java.util.Objects.requireNonNull;
 
@@ -26,7 +27,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.Set;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 
 /**
  * A mutable version of {@link ImmutableOffsetMap}. It inherits the set of mappings from the immutable version and
@@ -318,15 +320,13 @@ public abstract class MutableOffsetMap<K, V> extends AbstractMap<K, V> implement
         }
     }
 
-    @Nonnull
     @Override
-    public final Set<Entry<K, V>> entrySet() {
+    public final @NonNull Set<Entry<K, V>> entrySet() {
         return new EntrySet();
     }
 
-    @Nonnull
     @Override
-    public Map<K, V> toUnmodifiableMap() {
+    public @NonNull Map<K, V> toUnmodifiableMap() {
         if (removed == 0 && newKeys.isEmpty()) {
             // Make sure next modification clones the array, as we leak it to the map we return.
             needClone = true;
@@ -478,9 +478,8 @@ public abstract class MutableOffsetMap<K, V> extends AbstractMap<K, V> implement
         return true;
     }
 
-    @Nonnull
     @Override
-    public final Set<K> keySet() {
+    public final @NonNull Set<K> keySet() {
         return new KeySet();
     }
 
@@ -500,9 +499,8 @@ public abstract class MutableOffsetMap<K, V> extends AbstractMap<K, V> implement
     }
 
     private final class EntrySet extends AbstractSet<Entry<K, V>> {
-        @Nonnull
         @Override
-        public Iterator<Entry<K, V>> iterator() {
+        public @NonNull Iterator<Entry<K, V>> iterator() {
             return new AbstractSetIterator<Entry<K, V>>() {
                 @Override
                 public Entry<K, V> next() {
@@ -569,9 +567,8 @@ public abstract class MutableOffsetMap<K, V> extends AbstractMap<K, V> implement
     }
 
     private final class KeySet extends AbstractSet<K> {
-        @Nonnull
         @Override
-        public Iterator<K> iterator() {
+        public @NonNull Iterator<K> iterator() {
             return new AbstractSetIterator<K>() {
                 @Override
                 public K next() {
@@ -590,8 +587,8 @@ public abstract class MutableOffsetMap<K, V> extends AbstractMap<K, V> implement
         private final Iterator<Entry<K, Integer>> oldIterator = offsets.entrySet().iterator();
         private final Iterator<K> newIterator = newKeys.keySet().iterator();
         private int expectedModCount = modCount;
-        private K currentKey;
-        private K nextKey;
+        private @Nullable K currentKey = null;
+        private @Nullable K nextKey;
 
         AbstractSetIterator() {
             updateNextKey();
@@ -624,9 +621,8 @@ public abstract class MutableOffsetMap<K, V> extends AbstractMap<K, V> implement
 
         @Override
         public final void remove() {
-            requireNonNull(currentKey != null);
-
             checkModCount();
+            checkState(currentKey != null);
             final Integer offset = offsets.get(currentKey);
             if (offset != null) {
                 cloneArray();
index e2a060e7f87d38d6ec5067e334159a4b76683e16..6e834f0b3a37d7a63c2434507b45da0f27549847 100644 (file)
@@ -11,6 +11,7 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.Beta;
 import com.google.common.base.MoreObjects;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
@@ -29,7 +30,7 @@ public final class ObjectRegistry<T> {
     private final Set<ObjectRegistration<? extends T>> unmodifiableView;
     private final String name;
 
-    private ObjectRegistry(final String name, Set<ObjectRegistration<? extends T>> objects) {
+    private ObjectRegistry(final String name, final Set<ObjectRegistration<? extends T>> objects) {
         this.name = requireNonNull(name);
         this.objects = requireNonNull(objects);
         this.unmodifiableView = Collections.unmodifiableSet(objects);
@@ -71,7 +72,7 @@ public final class ObjectRegistry<T> {
     }
 
     private static final class Reg<T> extends AbstractObjectRegistration<T> {
-        private @Nullable @javax.annotation.Nullable Consumer<ObjectRegistration<? super T>> removeCall;
+        private @Nullable Consumer<ObjectRegistration<? super T>> removeCall;
 
         Reg(final T instance, final Consumer<ObjectRegistration<? super T>> removeCall) {
             super(instance);
@@ -79,6 +80,7 @@ public final class ObjectRegistry<T> {
         }
 
         @Override
+        @SuppressFBWarnings("NP_STORE_INTO_NONNULL_FIELD")
         protected void removeRegistration() {
             removeCall.accept(this);
             // Do not retail reference to that state
index df6c35e3f649dd7baa5569c2ce2939fba1ea084c..52c9dc94d53b339dcd15dc43cf7f7decee8e004a 100644 (file)
@@ -23,7 +23,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import javax.annotation.Nonnull;
 
 final class OffsetMapCache {
     /*
@@ -33,7 +32,7 @@ final class OffsetMapCache {
     private static final LoadingCache<List<?>, Map<?, Integer>> ORDERED_CACHE =
             CacheBuilder.newBuilder().weakValues().build(new CacheLoader<List<?>, Map<?, Integer>>() {
                 @Override
-                public Map<?, Integer> load(@Nonnull final List<?> key) {
+                public Map<?, Integer> load(final List<?> key) {
                     return createMap(key);
                 }
             });
index 824dbe6e47a7b133fd661712be971c2e2af4218b..0eb509e98b812f33ff2d79718d8af8d4a0e9de53 100644 (file)
@@ -8,8 +8,10 @@
 package org.opendaylight.yangtools.util;
 
 import com.google.common.annotations.Beta;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Optional;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 
 /**
  * Utility class for storing an optional boolean in a single byte value. This cuts down the memory requirement quite
@@ -94,9 +96,10 @@ public final class OptionalBoolean {
     /**
      * Convert a field value to a nullable {@link Boolean}. Similar to {@code Optional.orElse(null)}.
      *
-     * @param value Fied value.
+     * @param value Field value.
      * @return Nullable Boolean.
      */
+    @SuppressFBWarnings("NP_BOOLEAN_RETURN_NULL")
     public static @Nullable Boolean toNullable(final byte value) {
         switch (value) {
             case ABSENT:
@@ -117,7 +120,7 @@ public final class OptionalBoolean {
      * @return Optional {@link Boolean}.
      * @throws IllegalArgumentException if value is invalid.
      */
-    public static Optional<Boolean> toOptional(final byte value) {
+    public static @NonNull Optional<Boolean> toOptional(final byte value) {
         switch (value) {
             case ABSENT:
                 return Optional.empty();
@@ -137,7 +140,7 @@ public final class OptionalBoolean {
      * @return Boolean-compatible string, or "absent".
      * @throws IllegalArgumentException if value is invalid.
      */
-    public static String toString(final byte value) {
+    public static @NonNull String toString(final byte value) {
         switch (value) {
             case ABSENT:
                 return "absent";
index 702fd00730bbed13b91ab314c45d038cb5eaa4a9..25025b364956e42504bac0377d18e4bcb2c62c07 100644 (file)
@@ -14,7 +14,6 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Map;
 import java.util.Set;
-import javax.annotation.Nonnull;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import tech.pantheon.triemap.MutableTrieMap;
@@ -89,7 +88,7 @@ final class ReadWriteTrieMap<K, V> extends ForwardingMap<K, V> {
 
     @Override
     @SuppressWarnings("checkstyle:parameterName")
-    public void putAll(@Nonnull final Map<? extends K, ? extends V> m) {
+    public void putAll(final Map<? extends K, ? extends V> m) {
         for (Entry<? extends K, ? extends V> e : m.entrySet()) {
             put(e.getKey(), e.getValue());
         }
index ddd31ebdb869672e3008fafd8f8292deec43282c..711b557d31780e2da68873746f87a3952676eb1c 100644 (file)
@@ -14,8 +14,8 @@ import java.util.AbstractMap.SimpleEntry;
 import java.util.ArrayDeque;
 import java.util.Deque;
 import java.util.Map.Entry;
-import javax.annotation.Nullable;
 import javax.annotation.concurrent.ThreadSafe;
+import org.eclipse.jdt.annotation.Nullable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -107,7 +107,7 @@ public final class RecursiveObjectLeaker {
     // BEWARE: this method returns incpmpletely-initialized objects (that is the purpose of this class).
     //
     //         BE VERY CAREFUL WHAT OBJECT STATE YOU TOUCH
-    public static @Nullable <T> T lookup(final Object key, final Class<T> requiredClass) {
+    public static <T> @Nullable T lookup(final Object key, final Class<T> requiredClass) {
         final Deque<Entry<?, Object>> stack = STACK.get();
         if (stack != null) {
             for (Entry<?, Object> e : stack) {
index 8e36661c3ac61b146d64985076cb417d73cad798..8fa39312390cfdf2df6b3955a639f2316c750a1c 100644 (file)
@@ -17,7 +17,7 @@ import com.google.common.cache.LoadingCache;
 import java.io.Serializable;
 import java.util.AbstractMap.SimpleImmutableEntry;
 import java.util.Map;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
 
 /**
  * Implementation of the {@link Map} interface which stores a single mapping. The key set is shared among all instances
@@ -35,9 +35,8 @@ public abstract class SharedSingletonMap<K, V> implements Serializable, Unmodifi
             super(key, value);
         }
 
-        @Nonnull
         @Override
-        public ModifiableMapPhase<K, V> toModifiableMap() {
+        public @NonNull ModifiableMapPhase<K, V> toModifiableMap() {
             return MutableOffsetMap.orderedCopyOf(this);
         }
     }
@@ -49,9 +48,8 @@ public abstract class SharedSingletonMap<K, V> implements Serializable, Unmodifi
             super(key, value);
         }
 
-        @Nonnull
         @Override
-        public ModifiableMapPhase<K, V> toModifiableMap() {
+        public @NonNull ModifiableMapPhase<K, V> toModifiableMap() {
             return MutableOffsetMap.unorderedCopyOf(this);
         }
     }
@@ -60,7 +58,7 @@ public abstract class SharedSingletonMap<K, V> implements Serializable, Unmodifi
     private static final LoadingCache<Object, SingletonSet<Object>> CACHE = CacheBuilder.newBuilder().weakValues()
             .build(new CacheLoader<Object, SingletonSet<Object>>() {
                 @Override
-                public SingletonSet<Object> load(@Nonnull final Object key) {
+                public SingletonSet<Object> load(final Object key) {
                     return SingletonSet.of(key);
                 }
             });
@@ -96,21 +94,18 @@ public abstract class SharedSingletonMap<K, V> implements Serializable, Unmodifi
         return new Unordered<>(e.getKey(), e.getValue());
     }
 
-    @Nonnull
     @Override
-    public final SingletonSet<Entry<K, V>> entrySet() {
+    public final @NonNull SingletonSet<Entry<K, V>> entrySet() {
         return SingletonSet.of(new SimpleImmutableEntry<>(keySet.getElement(), value));
     }
 
-    @Nonnull
     @Override
-    public final SingletonSet<K> keySet() {
+    public final @NonNull SingletonSet<K> keySet() {
         return keySet;
     }
 
-    @Nonnull
     @Override
-    public final SingletonSet<V> values() {
+    public final @NonNull SingletonSet<V> values() {
         return SingletonSet.of(value);
     }
 
@@ -153,7 +148,7 @@ public abstract class SharedSingletonMap<K, V> implements Serializable, Unmodifi
 
     @Override
     @SuppressWarnings("checkstyle:parameterName")
-    public final void putAll(@Nonnull final Map<? extends K, ? extends V> m) {
+    public final void putAll(final Map<? extends K, ? extends V> m) {
         throw new UnsupportedOperationException();
     }
 
index 091ae4c1dba6b3e4ca67a3021a36c43b5043fbea..b809978ee0a879e9db2940a535b5d4ff7144037e 100644 (file)
@@ -16,7 +16,9 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.Set;
 import java.util.Spliterator;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.concepts.Immutable;
 
 /**
@@ -43,17 +45,17 @@ public abstract class SingletonSet<E> implements Set<E>, Immutable, Serializable
         }
 
         @Override
-        public Object getElement() {
+        public @Nullable Object getElement() {
             return null;
         }
 
         @Override
-        public Spliterator<Object> spliterator() {
+        public @NonNull Spliterator<Object> spliterator() {
             return SingletonSpliterators.immutableOfNull();
         }
 
         @Override
-        public String toString() {
+        public @NonNull String toString() {
             return "[null]";
         }
 
@@ -63,14 +65,11 @@ public abstract class SingletonSet<E> implements Set<E>, Immutable, Serializable
     };
 
     @SuppressWarnings("unchecked")
-    public static <E> SingletonSet<E> of(@Nonnull final E element) {
-        if (element == null) {
-            return (SingletonSet<E>) NULL_SINGLETON;
-        }
-        return new RegularSingletonSet<>(element);
+    public static <E> @NonNull SingletonSet<E> of(final @Nullable E element) {
+        return element == null ? (SingletonSet<E>) NULL_SINGLETON : new RegularSingletonSet<>(element);
     }
 
-    public abstract E getElement();
+    public abstract @Nullable E getElement();
 
     @Override
     public final int size() {
@@ -83,23 +82,21 @@ public abstract class SingletonSet<E> implements Set<E>, Immutable, Serializable
     }
 
     @Override
-    public final Iterator<E> iterator() {
+    public final @NonNull Iterator<E> iterator() {
         return Iterators.singletonIterator(getElement());
     }
 
     @Override
-    public abstract Spliterator<E> spliterator();
+    public abstract @NonNull Spliterator<E> spliterator();
 
-    @Nonnull
     @Override
-    public final Object[] toArray() {
+    public final @NonNull Object[] toArray() {
         return new Object[] { getElement() };
     }
 
-    @Nonnull
     @SuppressWarnings({ "unchecked", "checkstyle:parameterName" })
     @Override
-    public final <T> T[] toArray(@Nonnull final T[] a) {
+    public final <T> @NonNull T[] toArray(final T[] a) {
         if (a.length > 0) {
             a[0] = (T)getElement();
             return a;
@@ -122,7 +119,7 @@ public abstract class SingletonSet<E> implements Set<E>, Immutable, Serializable
 
     @Override
     @SuppressWarnings("checkstyle:parameterName")
-    public final boolean containsAll(@Nonnull final Collection<?> c) {
+    public final boolean containsAll(final Collection<?> c) {
         if (c.isEmpty()) {
             return true;
         }
@@ -135,19 +132,19 @@ public abstract class SingletonSet<E> implements Set<E>, Immutable, Serializable
 
     @Override
     @SuppressWarnings("checkstyle:parameterName")
-    public final boolean addAll(@Nonnull final Collection<? extends E> c) {
+    public final boolean addAll(final Collection<? extends E> c) {
         throw new UnsupportedOperationException();
     }
 
     @Override
     @SuppressWarnings("checkstyle:parameterName")
-    public final boolean retainAll(@Nonnull final Collection<?> c) {
+    public final boolean retainAll(final Collection<?> c) {
         throw new UnsupportedOperationException();
     }
 
     @Override
     @SuppressWarnings("checkstyle:parameterName")
-    public final boolean removeAll(@Nonnull final Collection<?> c) {
+    public final boolean removeAll(final Collection<?> c) {
         throw new UnsupportedOperationException();
     }
 
@@ -173,7 +170,7 @@ public abstract class SingletonSet<E> implements Set<E>, Immutable, Serializable
         return s.size() == 1 && otherContains(s);
     }
 
-    private boolean otherContains(final Collection<?> other) {
+    private boolean otherContains(final @NonNull Collection<?> other) {
         try {
             return other.contains(getElement());
         } catch (ClassCastException | NullPointerException e) {
@@ -181,8 +178,10 @@ public abstract class SingletonSet<E> implements Set<E>, Immutable, Serializable
         }
     }
 
+    @NonNullByDefault
     private static final class RegularSingletonSet<E> extends SingletonSet<E> {
         private static final long serialVersionUID = 1L;
+
         private final E element;
 
         RegularSingletonSet(final E element) {
@@ -191,7 +190,7 @@ public abstract class SingletonSet<E> implements Set<E>, Immutable, Serializable
 
         @Override
         @SuppressWarnings("checkstyle:parameterName")
-        public boolean contains(final Object o) {
+        public boolean contains(final @Nullable Object o) {
             return element.equals(o);
         }
 
index d5a9a27c24852c9dc105fc096e2a27a487bbc032..ba5404db164636b54b174906adc4da511431b9d3 100644 (file)
@@ -18,7 +18,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
 
 /**
  * An unmodifiable view over a {@link Collection}. Unlike the view returned via
@@ -33,8 +33,8 @@ import javax.annotation.Nonnull;
  */
 public final class UnmodifiableCollection<E> implements Collection<E>, Serializable {
     private static final long serialVersionUID = 1L;
-    private static final Class<?> UNMODIFIABLE_COLLECTION_CLASS;
-    private static final Collection<Class<?>> SINGLETON_CLASSES;
+    private static final @NonNull Class<?> UNMODIFIABLE_COLLECTION_CLASS;
+    private static final @NonNull Collection<Class<?>> SINGLETON_CLASSES;
 
     static {
         UNMODIFIABLE_COLLECTION_CLASS = Collections.unmodifiableCollection(new ArrayList<>()).getClass();
@@ -45,9 +45,9 @@ public final class UnmodifiableCollection<E> implements Collection<E>, Serializa
         SINGLETON_CLASSES = b.build();
     }
 
-    private final Collection<E> delegate;
+    private final @NonNull Collection<E> delegate;
 
-    private UnmodifiableCollection(final Collection<E> delegate) {
+    private UnmodifiableCollection(final @NonNull Collection<E> delegate) {
         this.delegate = requireNonNull(delegate);
     }
 
@@ -57,8 +57,9 @@ public final class UnmodifiableCollection<E> implements Collection<E>, Serializa
      *
      * @param collection Target collection
      * @return An unmodifiable view of the collection
+     * @throws NullPointerException if {@code collection} is null
      */
-    public static <T> Collection<T> create(@Nonnull final Collection<T> collection) {
+    public static <T> @NonNull Collection<T> create(final @NonNull Collection<T> collection) {
         if (collection instanceof UnmodifiableCollection || collection instanceof ImmutableCollection
                 || Collections.EMPTY_LIST == collection || Collections.EMPTY_SET == collection
                 || UNMODIFIABLE_COLLECTION_CLASS.isInstance(collection)
@@ -69,9 +70,8 @@ public final class UnmodifiableCollection<E> implements Collection<E>, Serializa
         return new UnmodifiableCollection<>(collection);
     }
 
-    @Nonnull
     @Override
-    public Iterator<E> iterator() {
+    public @NonNull Iterator<E> iterator() {
         return Iterators.unmodifiableIterator(delegate.iterator());
     }
 
@@ -98,13 +98,13 @@ public final class UnmodifiableCollection<E> implements Collection<E>, Serializa
 
     @Override
     @SuppressWarnings("checkstyle:parameterName")
-    public <T> T[] toArray(@Nonnull final T[] a) {
+    public <T> T[] toArray(final T[] a) {
         return delegate.toArray(a);
     }
 
     @Override
     @SuppressWarnings("checkstyle:parameterName")
-    public boolean containsAll(@Nonnull final Collection<?> c) {
+    public boolean containsAll(final Collection<?> c) {
         return delegate.containsAll(c);
     }
 
@@ -116,7 +116,7 @@ public final class UnmodifiableCollection<E> implements Collection<E>, Serializa
 
     @Override
     @SuppressWarnings("checkstyle:parameterName")
-    public boolean addAll(@Nonnull final Collection<? extends E> c) {
+    public boolean addAll(final Collection<? extends E> c) {
         throw new UnsupportedOperationException();
     }
 
@@ -128,13 +128,13 @@ public final class UnmodifiableCollection<E> implements Collection<E>, Serializa
 
     @Override
     @SuppressWarnings("checkstyle:parameterName")
-    public boolean removeAll(@Nonnull final Collection<?> c) {
+    public boolean removeAll(final Collection<?> c) {
         throw new UnsupportedOperationException();
     }
 
     @Override
     @SuppressWarnings("checkstyle:parameterName")
-    public boolean retainAll(@Nonnull final Collection<?> c) {
+    public boolean retainAll(final Collection<?> c) {
         throw new UnsupportedOperationException();
     }
 
@@ -144,7 +144,7 @@ public final class UnmodifiableCollection<E> implements Collection<E>, Serializa
     }
 
     @Override
-    public String toString() {
+    public @NonNull String toString() {
         return "UnmodifiableCollection{" + delegate + "}";
     }
 }
index 09dc364ace5f86ea4561ffa403c6d46cc019e51f..98d38fadfd411fba4e53e522cda600026b8053d4 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.yangtools.util;
 
 import com.google.common.annotations.Beta;
 import java.util.Map;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.Immutable;
 
 /**
@@ -26,5 +26,5 @@ public interface UnmodifiableMapPhase<K, V> extends Map<K, V>, Immutable {
      *
      * @return An modifiable version of this map.
      */
-    @Nonnull ModifiableMapPhase<K, V> toModifiableMap();
+    @NonNull ModifiableMapPhase<K, V> toModifiableMap();
 }
index ab3bdb1a09e154a1fe3ff5be321b71bb3055cd9f..e79409e197ebae69acd8dade6c233e3e4a39284d 100644 (file)
@@ -5,7 +5,6 @@
  * 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.util.concurrent;
 
 import static java.util.Objects.requireNonNull;
@@ -16,8 +15,8 @@ import com.google.common.util.concurrent.ListenableFutureTask;
 import java.util.concurrent.Callable;
 import java.util.concurrent.Executor;
 import java.util.concurrent.FutureTask;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -53,22 +52,22 @@ public class AsyncNotifyingListenableFutureTask<V> extends FutureTask<V> impleme
         /**
          * The executor used to run listener callbacks.
          */
-        private final Executor listenerExecutor;
+        private final @NonNull Executor listenerExecutor;
 
         private DelegatingAsyncNotifyingListenableFutureTask(final Callable<V> callable,
-                final Executor listenerExecutor) {
+                final @NonNull Executor listenerExecutor) {
             super(callable);
             this.listenerExecutor = requireNonNull(listenerExecutor);
         }
 
         private DelegatingAsyncNotifyingListenableFutureTask(final Runnable runnable, @Nullable final V result,
-                final Executor listenerExecutor) {
+                final @NonNull Executor listenerExecutor) {
             super(runnable, result);
             this.listenerExecutor = requireNonNull(listenerExecutor);
         }
 
         @Override
-        public void addListener(@Nonnull final Runnable listener, @Nonnull final Executor executor) {
+        public void addListener(final Runnable listener,  final Executor executor) {
             // Wrap the listener Runnable in a DelegatingRunnable. If the specified executor is one that
             // runs tasks in the same thread as the caller submitting the task
             // (e.g. {@link com.google.common.util.concurrent.MoreExecutors#sameThreadExecutor}) and the
@@ -119,11 +118,11 @@ public class AsyncNotifyingListenableFutureTask<V> extends FutureTask<V> impleme
      */
     private final ExecutionList executionList = new ExecutionList();
 
-    private AsyncNotifyingListenableFutureTask(final Callable<V> callable) {
+    private AsyncNotifyingListenableFutureTask(final @NonNull Callable<V> callable) {
         super(callable);
     }
 
-    private AsyncNotifyingListenableFutureTask(final Runnable runnable, final V result) {
+    private AsyncNotifyingListenableFutureTask(final @NonNull Runnable runnable, final @Nullable V result) {
         super(runnable, result);
     }
 
@@ -135,7 +134,7 @@ public class AsyncNotifyingListenableFutureTask<V> extends FutureTask<V> impleme
      * @param listenerExecutor the executor used to run listener callbacks asynchronously.
      *                         If null, no executor is used.
      */
-    public static <V> AsyncNotifyingListenableFutureTask<V> create(final Callable<V> callable,
+    public static <V> @NonNull AsyncNotifyingListenableFutureTask<V> create(final @NonNull Callable<V> callable,
             @Nullable final Executor listenerExecutor) {
         if (listenerExecutor == null) {
             return new AsyncNotifyingListenableFutureTask<>(callable);
@@ -153,8 +152,8 @@ public class AsyncNotifyingListenableFutureTask<V> extends FutureTask<V> impleme
      * @param listenerExecutor the executor used to run listener callbacks asynchronously.
      *                         If null, no executor is used.
      */
-    public static <V> AsyncNotifyingListenableFutureTask<V> create(final Runnable runnable, @Nullable final V result,
-            @Nullable final Executor listenerExecutor) {
+    public static <V> @NonNull AsyncNotifyingListenableFutureTask<V> create(final @NonNull Runnable runnable,
+            @Nullable final V result, @Nullable final Executor listenerExecutor) {
         if (listenerExecutor == null) {
             return new AsyncNotifyingListenableFutureTask<>(runnable, result);
         }
@@ -162,7 +161,7 @@ public class AsyncNotifyingListenableFutureTask<V> extends FutureTask<V> impleme
     }
 
     @Override
-    public void addListener(@Nonnull final Runnable listener, @Nonnull final Executor executor) {
+    public void addListener(final Runnable listener, final Executor executor) {
         executionList.add(listener, executor);
     }
 
index 48b2a5a8ccfb0088078d911fc5b8346e1f52b13f..1be75009131ec3dc623bb6be7393ad6e2d692f88 100644 (file)
@@ -5,7 +5,6 @@
  * 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.util.concurrent;
 
 import static java.util.Objects.requireNonNull;
@@ -19,43 +18,35 @@ import java.util.concurrent.Callable;
 import java.util.concurrent.Executor;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 
 /**
- * An {@link com.google.common.util.concurrent.ListeningExecutorService}
- * implementation that also allows for an {@link Executor} to be specified on
- * construction that is used to execute {@link ListenableFuture} callback
- * Runnables, registered via
- * {@link com.google.common.util.concurrent.Futures#addCallback} or
- * {@link ListenableFuture#addListener} directly, asynchronously when a task
- * that is run on this executor completes. This is useful when you want to
- * guarantee listener callback executions are off-loaded onto another thread to
- * avoid blocking the thread that completed the task, as a common use case is to
- * pass an executor that runs tasks in the same thread as the caller (ie
- * <code>MoreExecutors#sameThreadExecutor</code>}) to
- * {@link ListenableFuture#addListener}.
+ * An {@link com.google.common.util.concurrent.ListeningExecutorService} implementation that also allows
+ * for an {@link Executor} to be specified on construction that is used to execute {@link ListenableFuture} callback
+ * Runnables, registered via {@link com.google.common.util.concurrent.Futures#addCallback} or
+ * {@link ListenableFuture#addListener} directly, asynchronously when a task that is run on this executor completes.
+ * This is useful when you want to guarantee listener callback executions are off-loaded onto another thread to avoid
+ * blocking the thread that completed the task, as a common use case is to pass an executor that runs tasks in the same
+ * thread as the caller (i.e. {@code MoreExecutors#sameThreadExecutor}) to {@link ListenableFuture#addListener}.
  *
  * <p>
- * Most commonly, this class would be used in lieu of
- * <code>MoreExecutors#listeningDecorator</code> when the underlying delegate
- * Executor is single-threaded, in which case, you may not want ListenableFuture
- * callbacks to block the single thread.
+ * Most commonly, this class would be used in lieu of {@code MoreExecutors#listeningDecorator} when the underlying
+ * delegate Executor is single-threaded, in which case, you may not want ListenableFuture callbacks to block the single
+ * thread.
  *
  * <p>
- * Note: the Executor specified on construction does not replace the Executor
- * specified in {@link ListenableFuture#addListener}. The latter Executor is
- * still used however, if it is detected that the listener Runnable would
- * execute in the thread that completed the task, the listener is executed on
- * Executor specified on construction.
+ * Note: the Executor specified on construction does not replace the Executor specified
+ * in {@link ListenableFuture#addListener}. The latter Executor is still used however, if it is detected that
+ * the listener Runnable would execute in the thread that completed the task, the listener is executed on Executor
+ * specified on construction.
  *
  * @author Thomas Pantelis
  * @see AsyncNotifyingListenableFutureTask
  */
 public class AsyncNotifyingListeningExecutorService extends AbstractListeningExecutorService {
-
-    private final ExecutorService delegate;
-    private final Executor listenableFutureExecutor;
+    private final @NonNull ExecutorService delegate;
+    private final @Nullable Executor listenableFutureExecutor;
 
     /**
      * Constructor.
@@ -64,39 +55,31 @@ public class AsyncNotifyingListeningExecutorService extends AbstractListeningExe
      * @param listenableFutureExecutor the executor used to run listener callbacks asynchronously.
      *     If null, no executor is used.
      */
-    public AsyncNotifyingListeningExecutorService(final ExecutorService delegate,
+    public AsyncNotifyingListeningExecutorService(final @NonNull ExecutorService delegate,
             @Nullable final Executor listenableFutureExecutor) {
         this.delegate = requireNonNull(delegate);
         this.listenableFutureExecutor = listenableFutureExecutor;
     }
 
-    /**
-     * Creates an {@link AsyncNotifyingListenableFutureTask} instance with the listener Executor.
-     *
-     * @param task the Callable to execute
-     */
-    private <T> AsyncNotifyingListenableFutureTask<T> newFutureTask(final Callable<T> task) {
-        return AsyncNotifyingListenableFutureTask.create(task, listenableFutureExecutor);
-    }
-
     /**
      * Creates an {@link AsyncNotifyingListenableFutureTask} instance with the listener Executor.
      *
      * @param task the Runnable to execute
      */
-    private <T> AsyncNotifyingListenableFutureTask<T> newFutureTask(final Runnable task, final T result) {
+    private <T> @NonNull AsyncNotifyingListenableFutureTask<T> newFutureTask(final @NonNull Runnable task,
+            final T result) {
         return AsyncNotifyingListenableFutureTask.create(task, result, listenableFutureExecutor);
     }
 
     /**
      * Returns the delegate ExecutorService.
      */
-    protected ExecutorService getDelegate() {
+    protected @NonNull ExecutorService getDelegate() {
         return delegate;
     }
 
     @Override
-    public boolean awaitTermination(final long timeout, @Nonnull final TimeUnit unit) throws InterruptedException {
+    public boolean awaitTermination(final long timeout, final TimeUnit unit) throws InterruptedException {
         return delegate.awaitTermination(timeout, unit);
     }
 
@@ -115,48 +98,44 @@ public class AsyncNotifyingListeningExecutorService extends AbstractListeningExe
         delegate.shutdown();
     }
 
-    @Nonnull
     @Override
     public List<Runnable> shutdownNow() {
         return delegate.shutdownNow();
     }
 
     @Override
-    public void execute(@Nonnull final Runnable command) {
+    public void execute(final Runnable command) {
         delegate.execute(command);
     }
 
-    @Nonnull
     @Override
     public <T> ListenableFuture<T> submit(final Callable<T> task) {
-        AsyncNotifyingListenableFutureTask<T> futureTask = newFutureTask(task);
+        final AsyncNotifyingListenableFutureTask<T> futureTask = AsyncNotifyingListenableFutureTask.create(
+            requireNonNull(task), listenableFutureExecutor);
         delegate.execute(futureTask);
         return futureTask;
     }
 
-    @Nonnull
     @Override
     public ListenableFuture<?> submit(final Runnable task) {
-        AsyncNotifyingListenableFutureTask<Void> futureTask = newFutureTask(task, null);
+        final AsyncNotifyingListenableFutureTask<Void> futureTask = newFutureTask(requireNonNull(task), null);
         delegate.execute(futureTask);
         return futureTask;
     }
 
-    @Nonnull
     @Override
     public <T> ListenableFuture<T> submit(final Runnable task, final T result) {
-        AsyncNotifyingListenableFutureTask<T> futureTask = newFutureTask(task, result);
+        final AsyncNotifyingListenableFutureTask<T> futureTask = newFutureTask(requireNonNull(task), result);
         delegate.execute(futureTask);
         return futureTask;
     }
 
-    protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+    protected @NonNull ToStringHelper addToStringAttributes(final @NonNull ToStringHelper toStringHelper) {
         return toStringHelper;
     }
 
     @Override
     public final String toString() {
-        return addToStringAttributes(MoreObjects.toStringHelper(this)
-                .add("delegate", delegate)).toString();
+        return addToStringAttributes(MoreObjects.toStringHelper(this).add("delegate", delegate)).toString();
     }
 }
index fc17d890f5ef51b5e5e889f57ae0e56a96c5d6f4..de4a91e5a80605faa49b2d8fbb36234f38a36754 100644 (file)
@@ -5,13 +5,12 @@
  * 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.util.concurrent;
 
 import static com.google.common.base.Preconditions.checkState;
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.util.concurrent.ForwardingListenableFuture;
+import com.google.common.util.concurrent.ForwardingListenableFuture.SimpleForwardingListenableFuture;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
@@ -20,32 +19,30 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.function.Supplier;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 
 /**
- * An implementation of ListeningExecutorService that attempts to detect deadlock scenarios that
- * could occur if clients invoke the returned Future's <code>get</code> methods synchronously.
+ * An implementation of ListeningExecutorService that attempts to detect deadlock scenarios that could occur if clients
+ * invoke the returned Future's <code>get</code> methods synchronously.
  *
- * <p>Deadlock scenarios are most apt to occur with a backing single-threaded executor where setting of
- * the Future's result is executed on the single thread. Here's a scenario:
+ * <p>Deadlock scenarios are most apt to occur with a backing single-threaded executor where setting of the Future's
+ * result is executed on the single thread. Here's a scenario:
  * <ul>
  * <li>Client code is currently executing in an executor's single thread.</li>
  * <li>The client submits another task to the same executor.</li>
  * <li>The client calls <code>get()</code> synchronously on the returned Future</li>
  * </ul>
- * The second submitted task will never execute since the single thread is currently executing
- * the client code which is blocked waiting for the submitted task to complete. Thus, deadlock has
- * occurred.
+ * The second submitted task will never execute since the single thread is currently executing the client code which
+ * is blocked waiting for the submitted task to complete. Thus, deadlock has occurred.
  *
- * <p>This class prevents this scenario via the use of a ThreadLocal variable. When a task is invoked,
- * the ThreadLocal is set and, when a task completes, the ThreadLocal is cleared. Futures returned
- * from this class override the <code>get</code> methods to check if the ThreadLocal is set. If it is,
- * an ExecutionException is thrown with a custom cause.
+ * <p>This class prevents this scenario via the use of a ThreadLocal variable. When a task is invoked, the ThreadLocal
+ * is set and, when a task completes, the ThreadLocal is cleared. Futures returned from this class override
+ * the {@code get} methods to check if the ThreadLocal is set. If it is, an ExecutionException is thrown with a custom
+ * cause.
  *
- * <p>Note that the ThreadLocal is not removed automatically, so some state may be left hanging off of
- * threads which have encountered this class. If you need to clean that state up, use
- * {@link #cleanStateForCurrentThread()}.
+ * <p>Note that the ThreadLocal is not removed automatically, so some state may be left hanging off of threads which
+ * have encountered this class. If you need to clean that state up, use {@link #cleanStateForCurrentThread()}.
  *
  * @author Thomas Pantelis
  * @author Robert Varga
@@ -56,8 +53,8 @@ public class DeadlockDetectingListeningExecutorService extends AsyncNotifyingLis
      * tasks may be submitted to underlay and some to overlay service -- and the two cases need to
      * be discerned reliably.
      */
-    private final SettableBooleanThreadLocal deadlockDetector = new SettableBooleanThreadLocal();
-    private final Supplier<Exception> deadlockExceptionFunction;
+    private final @NonNull SettableBooleanThreadLocal deadlockDetector = new SettableBooleanThreadLocal();
+    private final @NonNull Supplier<Exception> deadlockExceptionFunction;
 
     /**
      * Constructor.
@@ -66,8 +63,8 @@ public class DeadlockDetectingListeningExecutorService extends AsyncNotifyingLis
      * @param deadlockExceptionSupplier Supplier that returns an Exception instance to set as the
      *             cause of the ExecutionException when a deadlock is detected.
      */
-    public DeadlockDetectingListeningExecutorService(final ExecutorService delegate,
-            @Nonnull final Supplier<Exception> deadlockExceptionSupplier) {
+    public DeadlockDetectingListeningExecutorService(final @NonNull ExecutorService delegate,
+            final @NonNull Supplier<Exception> deadlockExceptionSupplier) {
         this(delegate, deadlockExceptionSupplier, null);
     }
 
@@ -80,31 +77,28 @@ public class DeadlockDetectingListeningExecutorService extends AsyncNotifyingLis
      * @param listenableFutureExecutor the executor used to run listener callbacks asynchronously.
      *             If null, no executor is used.
      */
-    public DeadlockDetectingListeningExecutorService(final ExecutorService delegate,
-            @Nonnull final Supplier<Exception> deadlockExceptionSupplier,
+    public DeadlockDetectingListeningExecutorService(final @NonNull ExecutorService delegate,
+            @NonNull final Supplier<Exception> deadlockExceptionSupplier,
             @Nullable final Executor listenableFutureExecutor) {
         super(delegate, listenableFutureExecutor);
         this.deadlockExceptionFunction = requireNonNull(deadlockExceptionSupplier);
     }
 
     @Override
-    public void execute(@Nonnull final Runnable command) {
+    public void execute(final Runnable command) {
         getDelegate().execute(wrapRunnable(command));
     }
 
-    @Nonnull
     @Override
     public <T> ListenableFuture<T> submit(final Callable<T> task) {
         return wrapListenableFuture(super.submit(wrapCallable(task)));
     }
 
-    @Nonnull
     @Override
     public ListenableFuture<?> submit(final Runnable task) {
         return wrapListenableFuture(super.submit(wrapRunnable(task)));
     }
 
-    @Nonnull
     @Override
     public <T> ListenableFuture<T> submit(final Runnable task, final T result) {
         return wrapListenableFuture(super.submit(wrapRunnable(task), result));
@@ -118,14 +112,15 @@ public class DeadlockDetectingListeningExecutorService extends AsyncNotifyingLis
         deadlockDetector.remove();
     }
 
-    private SettableBoolean primeDetector() {
+    private @NonNull SettableBoolean primeDetector() {
         final SettableBoolean b = deadlockDetector.get();
         checkState(!b.isSet(), "Detector for {} has already been primed", this);
         b.set();
         return b;
     }
 
-    private Runnable wrapRunnable(final Runnable task) {
+    private @NonNull Runnable wrapRunnable(final @Nullable Runnable task) {
+        requireNonNull(task);
         return () -> {
             final SettableBoolean b = primeDetector();
             try {
@@ -136,18 +131,19 @@ public class DeadlockDetectingListeningExecutorService extends AsyncNotifyingLis
         };
     }
 
-    private <T> Callable<T> wrapCallable(final Callable<T> delagate) {
+    private <T> @NonNull Callable<T> wrapCallable(final @NonNull Callable<T> task) {
+        requireNonNull(task);
         return () -> {
             final SettableBoolean b = primeDetector();
             try {
-                return delagate.call();
+                return task.call();
             } finally {
                 b.reset();
             }
         };
     }
 
-    private <T> ListenableFuture<T> wrapListenableFuture(final ListenableFuture<T> delegate) {
+    private <T> @NonNull ListenableFuture<T> wrapListenableFuture(final @NonNull ListenableFuture<T> delegate) {
         /*
          * This creates a forwarding Future that overrides calls to get(...) to check, via the
          * ThreadLocal, if the caller is doing a blocking call on a thread from this executor. If
@@ -156,7 +152,7 @@ public class DeadlockDetectingListeningExecutorService extends AsyncNotifyingLis
          * practice somewhere, either on the client side for doing a blocking call or in the
          * framework's threading model.
          */
-        return new ForwardingListenableFuture.SimpleForwardingListenableFuture<T>(delegate) {
+        return new SimpleForwardingListenableFuture<T>(delegate) {
             @Override
             public T get() throws InterruptedException, ExecutionException {
                 checkDeadLockDetectorTL();
@@ -164,8 +160,8 @@ public class DeadlockDetectingListeningExecutorService extends AsyncNotifyingLis
             }
 
             @Override
-            public T get(final long timeout, @Nonnull final TimeUnit unit)
-                    throws InterruptedException, ExecutionException, TimeoutException {
+            public T get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException,
+                    TimeoutException {
                 checkDeadLockDetectorTL();
                 return super.get(timeout, unit);
             }
index 11253af8256fb3635105982f26eb953e7347d46f..35be7f7f302b160dcb964b056f22155cf6f69079 100644 (file)
@@ -5,7 +5,6 @@
  * 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.util.concurrent;
 
 import static com.google.common.base.Preconditions.checkArgument;
@@ -26,8 +25,8 @@ import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 import java.util.stream.Collectors;
-import javax.annotation.Nonnull;
 import javax.annotation.concurrent.GuardedBy;
+import org.eclipse.jdt.annotation.NonNull;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -80,7 +79,7 @@ public class QueuedNotificationManager<L, N> implements NotificationManager<L, N
          * @param listener the listener to invoke
          * @param notifications notifications to send
          */
-        void invokeListener(@Nonnull L listener, @Nonnull Collection<? extends N> notifications);
+        void invokeListener(@NonNull L listener, @NonNull Collection<? extends N> notifications);
     }
 
     private static final Logger LOG = LoggerFactory.getLogger(QueuedNotificationManager.class);
@@ -94,13 +93,14 @@ public class QueuedNotificationManager<L, N> implements NotificationManager<L, N
     private static final long TASK_WAIT_NANOS = TimeUnit.MILLISECONDS.toNanos(10);
 
     private final ConcurrentMap<ListenerKey<L>, NotificationTask> listenerCache = new ConcurrentHashMap<>();
-    private final BatchedInvoker<L, N> listenerInvoker;
-    private final Executor executor;
-    private final String name;
+    private final @NonNull BatchedInvoker<L, N> listenerInvoker;
+    private final @NonNull Executor executor;
+    private final @NonNull String name;
     private final int maxQueueCapacity;
 
-    private QueuedNotificationManager(final Executor executor, final BatchedInvoker<L, N> listenerInvoker,
-            final int maxQueueCapacity, final String name) {
+    private QueuedNotificationManager(final @NonNull Executor executor,
+            final @NonNull BatchedInvoker<L, N> listenerInvoker, final int maxQueueCapacity,
+            final @NonNull String name) {
         checkArgument(maxQueueCapacity > 0, "Invalid maxQueueCapacity %s must be > 0", maxQueueCapacity);
         this.executor = requireNonNull(executor);
         this.listenerInvoker = requireNonNull(listenerInvoker);
@@ -120,8 +120,8 @@ public class QueuedNotificationManager<L, N> implements NotificationManager<L, N
      */
     @Deprecated
     @SuppressWarnings("checkstyle:illegalCatch")
-    public QueuedNotificationManager(final Executor executor, final Invoker<L, N> listenerInvoker,
-            final int maxQueueCapacity, final String name) {
+    public QueuedNotificationManager(final @NonNull Executor executor, final @NonNull Invoker<L, N> listenerInvoker,
+            final int maxQueueCapacity, final @NonNull String name) {
         this(executor, (BatchedInvoker<L, N>)(listener, notifications) -> notifications.forEach(n -> {
             try {
                 listenerInvoker.invokeListener(listener, n);
@@ -141,8 +141,9 @@ public class QueuedNotificationManager<L, N> implements NotificationManager<L, N
      * @param maxQueueCapacity the capacity of each listener queue
      * @param name the name of this instance for logging info
      */
-    public static <L, N> QueuedNotificationManager<L, N> create(final Executor executor,
-            final BatchedInvoker<L, N> listenerInvoker, final int maxQueueCapacity, final String name) {
+    public static <L, N> QueuedNotificationManager<L, N> create(final @NonNull Executor executor,
+            final@NonNull  BatchedInvoker<L, N> listenerInvoker, final int maxQueueCapacity,
+            final @NonNull String name) {
         return new QueuedNotificationManager<>(executor, listenerInvoker, maxQueueCapacity, name);
     }
 
@@ -156,7 +157,7 @@ public class QueuedNotificationManager<L, N> implements NotificationManager<L, N
     /**
      * Returns the {@link Executor} to used for notification tasks.
      */
-    public Executor getExecutor() {
+    public @NonNull Executor getExecutor() {
         return executor;
     }
 
@@ -261,13 +262,13 @@ public class QueuedNotificationManager<L, N> implements NotificationManager<L, N
      * for instanceof.
      */
     private static final class ListenerKey<L> {
-        private final L listener;
+        private final @NonNull L listener;
 
         ListenerKey(final L listener) {
             this.listener = requireNonNull(listener);
         }
 
-        L getListener() {
+        @NonNull L getListener() {
             return listener;
         }
 
@@ -278,10 +279,7 @@ public class QueuedNotificationManager<L, N> implements NotificationManager<L, N
 
         @Override
         public boolean equals(final Object obj) {
-            if (obj == this) {
-                return true;
-            }
-            return obj instanceof ListenerKey<?> && listener == ((ListenerKey<?>) obj).listener;
+            return obj == this || obj instanceof ListenerKey<?> && listener == ((ListenerKey<?>) obj).listener;
         }
 
         @Override
@@ -295,25 +293,24 @@ public class QueuedNotificationManager<L, N> implements NotificationManager<L, N
      * listener.
      */
     private class NotificationTask implements Runnable {
-
         private final Lock lock = new ReentrantLock();
         private final Condition notEmpty = lock.newCondition();
         private final Condition notFull = lock.newCondition();
-        private final ListenerKey<L> listenerKey;
+        private final @NonNull ListenerKey<L> listenerKey;
 
         @GuardedBy("lock")
         private final Queue<N> queue = new ArrayDeque<>();
         @GuardedBy("lock")
         private boolean exiting;
 
-        NotificationTask(final ListenerKey<L> listenerKey, final Iterator<N> notifications) {
+        NotificationTask(final @NonNull ListenerKey<L> listenerKey, final @NonNull Iterator<N> notifications) {
             this.listenerKey = requireNonNull(listenerKey);
             while (notifications.hasNext()) {
                 queue.add(notifications.next());
             }
         }
 
-        Iterator<N> recoverItems() {
+        @NonNull Iterator<N> recoverItems() {
             // This violates @GuardedBy annotation, but is invoked only when the task is not started and will never
             // get started, hence this is safe.
             return queue.iterator();
@@ -328,7 +325,7 @@ public class QueuedNotificationManager<L, N> implements NotificationManager<L, N
             }
         }
 
-        boolean submitNotifications(final Iterator<N> notifications) throws InterruptedException {
+        boolean submitNotifications(final @NonNull Iterator<N> notifications) throws InterruptedException {
             final long start = System.nanoTime();
             final long deadline = start + GIVE_UP_NANOS;
 
@@ -400,7 +397,7 @@ public class QueuedNotificationManager<L, N> implements NotificationManager<L, N
             try {
                 // Loop until we've dispatched all the notifications in the queue.
                 while (true) {
-                    final Collection<N> notifications;
+                    final @NonNull Collection<N> notifications;
 
                     lock.lock();
                     try {
@@ -428,7 +425,7 @@ public class QueuedNotificationManager<L, N> implements NotificationManager<L, N
         }
 
         @SuppressWarnings("checkstyle:illegalCatch")
-        private void invokeListener(final Collection<N> notifications) {
+        private void invokeListener(final @NonNull Collection<N> notifications) {
             LOG.debug("{}: Invoking listener {} with notification: {}", name, listenerKey, notifications);
             try {
                 listenerInvoker.invokeListener(listenerKey.getListener(), notifications);
index 9cbd25b9e71f8d99ff3ef830fe258c007972bb36..966dae7a2aebb0fa2149cd5828087b0715f8b4f5 100644 (file)
@@ -5,7 +5,6 @@
  * 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.util.concurrent;
 
 import com.google.common.annotations.Beta;
@@ -13,7 +12,7 @@ import java.util.Collection;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
 
 /**
  * A {@link LinkedBlockingQueue} that tracks the largest queue size for debugging.
@@ -45,7 +44,7 @@ public class TrackingLinkedBlockingQueue<E> extends LinkedBlockingQueue<E> {
      * See {@link LinkedBlockingQueue#LinkedBlockingQueue(Collection)}.
      */
     @SuppressWarnings("checkstyle:parameterName")
-    public TrackingLinkedBlockingQueue(final Collection<? extends E> c) {
+    public TrackingLinkedBlockingQueue(final @NonNull Collection<? extends E> c) {
         super(c);
     }
 
@@ -79,7 +78,7 @@ public class TrackingLinkedBlockingQueue<E> extends LinkedBlockingQueue<E> {
 
     @Override
     @SuppressWarnings("checkstyle:parameterName")
-    public boolean offer(@Nonnull final E e) {
+    public boolean offer(final E e) {
         if (super.offer(e)) {
             updateLargestQueueSize();
             return true;
index 669715bd731eb224a23708b09f8add11b43f4e19..46c28490c85af3cff106abd83414d319fb93bbbd 100644 (file)
@@ -11,7 +11,6 @@ import com.google.common.annotations.Beta;
 import java.io.InputStream;
 import java.io.Reader;
 import java.nio.charset.Charset;
-import javax.annotation.Nonnull;
 import javax.xml.XMLConstants;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -21,6 +20,7 @@ import javax.xml.parsers.SAXParserFactory;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
+import org.eclipse.jdt.annotation.NonNull;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXNotRecognizedException;
 import org.xml.sax.SAXNotSupportedException;
@@ -32,7 +32,7 @@ import org.xml.sax.SAXNotSupportedException;
  */
 @Beta
 public final class UntrustedXML {
-    private static final DocumentBuilderFactory DBF;
+    private static final @NonNull DocumentBuilderFactory DBF;
 
     static {
         final DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
@@ -97,7 +97,7 @@ public final class UntrustedXML {
      * @return A new DocumentBuilder
      * @throws UnsupportedOperationException if the runtime fails to instantiate a good enough builder
      */
-    public static @Nonnull DocumentBuilder newDocumentBuilder() {
+    public static @NonNull DocumentBuilder newDocumentBuilder() {
         try {
             return DBF.newDocumentBuilder();
         } catch (ParserConfigurationException e) {
@@ -112,7 +112,7 @@ public final class UntrustedXML {
      * @return A new SAXParser
      * @throws UnsupportedOperationException if the runtime fails to instantiate a good enough builder
      */
-    public static @Nonnull SAXParser newSAXParser() {
+    public static @NonNull SAXParser newSAXParser() {
         try {
             return SPF.newSAXParser();
         } catch (ParserConfigurationException | SAXException e) {
@@ -127,7 +127,7 @@ public final class UntrustedXML {
      * @return A new XMLStreamReader
      * @throws XMLStreamException when the underlying factory throws it
      */
-    public static @Nonnull XMLStreamReader createXMLStreamReader(final InputStream stream) throws XMLStreamException {
+    public static @NonNull XMLStreamReader createXMLStreamReader(final InputStream stream) throws XMLStreamException {
         return XIF.createXMLStreamReader(stream);
     }
 
@@ -138,7 +138,7 @@ public final class UntrustedXML {
      * @return A new XMLStreamReader
      * @throws XMLStreamException when the underlying factory throws it
      */
-    public static @Nonnull XMLStreamReader createXMLStreamReader(final InputStream stream, final Charset charset)
+    public static @NonNull XMLStreamReader createXMLStreamReader(final InputStream stream, final Charset charset)
             throws XMLStreamException {
         return XIF.createXMLStreamReader(stream, charset.name());
     }
@@ -150,7 +150,7 @@ public final class UntrustedXML {
      * @return A new XMLStreamReader
      * @throws XMLStreamException when the underlying factory throws it
      */
-    public static @Nonnull XMLStreamReader createXMLStreamReader(final Reader reader) throws XMLStreamException {
+    public static @NonNull XMLStreamReader createXMLStreamReader(final Reader reader) throws XMLStreamException {
         return XIF.createXMLStreamReader(reader);
     }
 }
index e954795fbdddc48a68b65f9cb12efeb1d0109529..d973cc972b2d6d6a84be40fb309d54c5bacaa3fe 100644 (file)
@@ -5,7 +5,6 @@
  * 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.util.concurrent;
 
 import static org.junit.Assert.assertSame;
@@ -31,7 +30,6 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
-import javax.annotation.Nonnull;
 import org.junit.After;
 import org.junit.Test;
 import org.opendaylight.yangtools.util.concurrent.CommonTestUtils.Invoker;
@@ -150,7 +148,7 @@ public class AsyncNotifyingListeningExecutorServiceTest {
 
             @Override
             @SuppressWarnings("checkstyle:parameterName")
-            public void onFailure(@Nonnull final Throwable t) {
+            public void onFailure(final Throwable t) {
                 // Shouldn't happen
                 fail("Unexpected failure " + t);
             }
index e33b81be737043ff6cd8ed5ade381edcdbd218fa..e9962bfe18b03e9d5709afa1c13b5b2197f2f80d 100644 (file)
@@ -5,7 +5,6 @@
  * 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.util.concurrent;
 
 import static org.junit.Assert.assertEquals;
@@ -30,7 +29,6 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.Supplier;
-import javax.annotation.Nonnull;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -126,7 +124,7 @@ public class DeadlockDetectingListeningExecutorServiceTest {
 
             @Override
             @SuppressWarnings("checkstyle:parameterName")
-            public void onFailure(@Nonnull final Throwable t) {
+            public void onFailure(final Throwable t) {
                 caughtEx.set(t);
                 futureCompletedLatch.countDown();
             }