Annotate Collections.toArray() methods
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Fri, 30 Oct 2015 20:33:56 +0000 (16:33 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 24 Nov 2015 00:34:50 +0000 (19:34 -0500)
Both variants return @NonNull array references. The one with the
(T[]) parameter can also e annotated to require a @NonNull array
reference (or else it would just throw an NPE).

Note this covers only the array references themselves. The
contained element types will depend on what is passed in parameter

Change-Id: I31bed98a0b7d1df3486179a9e60cb8c73eb0038d
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/59421
Reviewed-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
common/org.eclipse.tracecompass.common.core/annotations/java/util/Collection.eea [new file with mode: 0644]
pcap/org.eclipse.tracecompass.tmf.pcap.core.tests/src/org/eclipse/tracecompass/tmf/pcap/core/tests/event/PcapEventFieldTest.java
pcap/org.eclipse.tracecompass.tmf.pcap.core/src/org/eclipse/tracecompass/internal/tmf/pcap/core/util/PcapEventFactory.java
statesystem/org.eclipse.tracecompass.segmentstore.core/src/org/eclipse/tracecompass/segmentstore/core/treemap/TreeMapStore.java

diff --git a/common/org.eclipse.tracecompass.common.core/annotations/java/util/Collection.eea b/common/org.eclipse.tracecompass.common.core/annotations/java/util/Collection.eea
new file mode 100644 (file)
index 0000000..1377560
--- /dev/null
@@ -0,0 +1,7 @@
+class java/util/Collection
+toArray
+ ()[Ljava/lang/Object;
+ ()[1Ljava/lang/Object;
+toArray
+ <T:Ljava/lang/Object;>([TT;)[TT;
+ <T:Ljava/lang/Object;>([1TT;)[1TT;
index 9f8757b4e236b6d23612643fcc7a8b8857d1697c..269932328b61f43e0561d71465c9692b8c5939c8 100644 (file)
@@ -233,11 +233,7 @@ public class PcapEventFieldTest {
             localPacket = localPacket.getChildPacket();
         }
 
-        ITmfEventField[] fieldArray = fieldList.toArray(new ITmfEventField[fieldList.size()]);
-        if (fieldArray == null) {
-            return new ITmfEventField[0];
-        }
-        return fieldArray;
+        return fieldList.toArray(new ITmfEventField[fieldList.size()]);
     }
 
 }
index fd560a716897358a7842b6d5bab905098ed2c531..91f47dd6e48269c8ee67567c4bae1d427a94f422 100644 (file)
@@ -46,7 +46,6 @@ import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
  */
 public class PcapEventFactory {
 
-    private static final ITmfEventField[] EMPTY_FIELD_ARRAY = new ITmfEventField[0];
     private static final String EMPTY_STRING = ""; //$NON-NLS-1$
 
     private static final Map<PcapProtocol, TmfEventType> fEventTypes = new HashMap<>();
@@ -121,10 +120,6 @@ public class PcapEventFactory {
             localPacket = localPacket.getChildPacket();
         }
 
-        ITmfEventField[] fieldArray = fieldList.toArray(new ITmfEventField[fieldList.size()]);
-        if (fieldArray == null) {
-            return EMPTY_FIELD_ARRAY;
-        }
-        return fieldArray;
+        return fieldList.toArray(new ITmfEventField[fieldList.size()]);
     }
 }
index 0bca75b6f7ddc18b66a522c0ce7ebc09acf817f8..0b3921ee147378669cf7d888563e69bd73710083 100644 (file)
@@ -171,7 +171,7 @@ public class TreeMapStore<E extends ISegment> implements ISegmentStore<E> {
     }
 
     @Override
-    public <T> T[] toArray(T @Nullable[] a) {
+    public <T> T[] toArray(T[] a) {
         fLock.readLock().lock();
         try {
             return fStartTimesIndex.values().toArray(a);
This page took 0.02852 seconds and 5 git commands to generate.