common: Annotate some methods in ByteBuffer
authorMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tue, 24 Nov 2015 23:42:19 +0000 (18:42 -0500)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tue, 1 Dec 2015 15:56:20 +0000 (10:56 -0500)
Change-Id: Ib27143f9129b5be40a3bf996397c250509c24f40
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/61206
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
13 files changed:
common/org.eclipse.tracecompass.common.core/annotations/java/nio/ByteBuffer.eea [new file with mode: 0644]
ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/io/BitBufferIntTest.java
ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFPacketReaderTest.java
ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFStreamInputPacketIndexEntryTest.java
ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/IntegerEndiannessTest.java
ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/SequenceDeclaration2Test.java
ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/SequenceDefinition2Test.java
ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/StringDeclarationTest.java
ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/StringDefinitionTest.java
ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/StructDeclarationTest.java
ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/VariantDeclarationTest.java
ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/io/BitBuffer.java
pcap/org.eclipse.tracecompass.pcap.core/src/org/eclipse/tracecompass/internal/pcap/core/protocol/ethernet2/EthernetIIPacket.java

diff --git a/common/org.eclipse.tracecompass.common.core/annotations/java/nio/ByteBuffer.eea b/common/org.eclipse.tracecompass.common.core/annotations/java/nio/ByteBuffer.eea
new file mode 100644 (file)
index 0000000..c25f538
--- /dev/null
@@ -0,0 +1,13 @@
+class java/nio/ByteBuffer
+allocate
+ (I)Ljava/nio/ByteBuffer;
+ (I)L1java/nio/ByteBuffer;
+allocateDirect
+ (I)Ljava/nio/ByteBuffer;
+ (I)L1java/nio/ByteBuffer;
+wrap
+ ([B)Ljava/nio/ByteBuffer;
+ ([B)L1java/nio/ByteBuffer;
+wrap
+ ([BII)Ljava/nio/ByteBuffer;
+ ([BII)L1java/nio/ByteBuffer;
index 2f1d9bb35396fc372629bd34484aa2940639c01f..1c698e83e08745430b5bca48e4b01796230a7198 100644 (file)
@@ -42,9 +42,6 @@ public class BitBufferIntTest {
     @Before
     public void setUp() throws CTFException {
         ByteBuffer allocateDirect = ByteBuffer.allocateDirect(128);
-        if (allocateDirect == null) {
-            throw new IllegalStateException("Failed to allocate memory");
-        }
         fixture = new BitBuffer(allocateDirect);
         fixture.setByteOrder(ByteOrder.BIG_ENDIAN);
         fixture = createBuffer();
@@ -60,9 +57,6 @@ public class BitBufferIntTest {
             bytes[i] = (byte) (i % 0xff);
         }
         ByteBuffer wrap = ByteBuffer.wrap(bytes);
-        if (wrap == null) {
-            throw new IllegalStateException("Failed to allocate memory");
-        }
         BitBuffer fixture = new BitBuffer(wrap);
         fixture.position(1);
         return fixture;
index 197cd5eb9988257cf8a86e85ed9f5c03c47e4769..8d76ee260d6d089b4a3fc253cea45867e5d06a1c 100644 (file)
@@ -22,7 +22,6 @@ import java.util.List;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.common.core.NonNullUtils;
 import org.eclipse.tracecompass.ctf.core.CTFException;
 import org.eclipse.tracecompass.ctf.core.CTFStrings;
 import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
@@ -50,9 +49,7 @@ public class CTFPacketReaderTest {
     private static final StructDeclaration EMPTY_STRUCT = new StructDeclaration(8);
 
     private static @NonNull BitBuffer createBitBuffer(byte[] bytes) {
-        // TODO: annotate ByteBuffer.wrap
-        ByteBuffer bb = NonNullUtils.checkNotNull(ByteBuffer.wrap(bytes));
-        return new BitBuffer(bb);
+        return new BitBuffer(ByteBuffer.wrap(bytes));
     }
 
     /**
index 55e7611b68f87c66e04971ba2dc9fe4638431321..fd33e77c6047e6c571e977c0e345df9cfbdc94ab 100644 (file)
@@ -85,7 +85,6 @@ public class CTFStreamInputPacketIndexEntryTest {
         sd.addField("load_factor", new FloatDeclaration(24, 8, ByteOrder.nativeOrder(), 8));
         sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII));
         sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL));
-        @SuppressWarnings("null")
         BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
         bb.getByteBuffer().putInt(100);
         bb.getByteBuffer().putInt(200);
@@ -114,7 +113,6 @@ public class CTFStreamInputPacketIndexEntryTest {
         sd.addField("content_size", IntegerDeclaration.INT_32B_DECL);
         sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII));
         sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL));
-        @SuppressWarnings("null")
         BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
         bb.getByteBuffer().putInt(100);
         bb.getByteBuffer().putInt(200);
@@ -144,7 +142,6 @@ public class CTFStreamInputPacketIndexEntryTest {
         sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII));
         sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL));
         sd.addField("intruder", new StructDeclaration(8));
-        @SuppressWarnings("null")
         BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
         bb.getByteBuffer().putInt(100);
         bb.getByteBuffer().putInt(200);
@@ -174,7 +171,6 @@ public class CTFStreamInputPacketIndexEntryTest {
         sd.addField("content_size", IntegerDeclaration.INT_32B_DECL);
         sd.addField("target", StringDeclaration.getStringDeclaration(Encoding.ASCII));
         sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL));
-        @SuppressWarnings("null")
         BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
         bb.getByteBuffer().putInt(0);
         bb.getByteBuffer().put(("Test").getBytes());
@@ -200,7 +196,6 @@ public class CTFStreamInputPacketIndexEntryTest {
         sd.addField("content_size", IntegerDeclaration.INT_32B_DECL);
         sd.addField("device", StringDeclaration.getStringDeclaration(Encoding.ASCII));
         sd.addField("Enum", new EnumDeclaration(IntegerDeclaration.INT_8_DECL));
-        @SuppressWarnings("null")
         BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
         bb.getByteBuffer().putInt(-1);
         bb.getByteBuffer().putInt(0);
@@ -228,7 +223,6 @@ public class CTFStreamInputPacketIndexEntryTest {
         sd.addField("content_size", IntegerDeclaration.INT_32B_DECL);
         sd.addField("cpu_id", IntegerDeclaration.INT_32B_DECL);
         sd.addField("events_discarded", IntegerDeclaration.INT_32B_DECL);
-        @SuppressWarnings("null")
         BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
         bb.getByteBuffer().putInt(-1);
         bb.getByteBuffer().putInt(0);
@@ -259,7 +253,6 @@ public class CTFStreamInputPacketIndexEntryTest {
         final EnumDeclaration declaration = new EnumDeclaration(IntegerDeclaration.createDeclaration(16, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 8));
         declaration.add(313, 315, "CPU-PI");
         sd.addField("device", declaration);
-        @SuppressWarnings("null")
         BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
         bb.getByteBuffer().putInt(-1);
         bb.getByteBuffer().putInt(0);
@@ -285,7 +278,6 @@ public class CTFStreamInputPacketIndexEntryTest {
         sd.addField("content_size", IntegerDeclaration.INT_32B_DECL);
         final IDeclaration declaration = IntegerDeclaration.createDeclaration(16, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 8);
         sd.addField("device", declaration);
-        @SuppressWarnings("null")
         BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
         bb.getByteBuffer().putInt(-1);
         bb.getByteBuffer().putInt(0);
@@ -311,7 +303,6 @@ public class CTFStreamInputPacketIndexEntryTest {
         StructDeclaration sd = new StructDeclaration(8);
         sd.addField("timestamp_begin", IntegerDeclaration.INT_32B_DECL);
         sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL);
-        @SuppressWarnings("null")
         BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
 
         StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb);
index 695376316bb4c19924e58914c51b075e830d3d91..5f9625e67b72803e64f0d120508e9a93898234b3 100644 (file)
@@ -49,9 +49,6 @@ public class IntegerEndiannessTest {
     public void setUp() {
         bb = java.nio.ByteBuffer.allocateDirect(8);
         final ByteBuffer byb = bb;
-        if (byb == null) {
-            throw new IllegalStateException("Failed to allocate memory");
-        }
         bb.put((byte) 0xab);
         bb.put((byte) 0xcd);
         bb.put((byte) 0xef);
index 7b2295848d47d3946c6cb218dcf922c7b4b8dd4f..8b38957827ebf3d3356ec25be19912f677f43d6e 100644 (file)
@@ -58,9 +58,6 @@ public class SequenceDeclaration2Test {
         fixture = new SequenceDeclaration(FIELD_NAME, StringDeclaration.getStringDeclaration(Encoding.UTF8));
         byte array[] = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
         ByteBuffer byb = ByteBuffer.wrap(array);
-        if (byb == null) {
-            throw new IllegalStateException("Failed to allocate memory");
-        }
         input = new BitBuffer(byb);
     }
 
index 5258ccf105698a95e357ed4fcde79450858fdf10..47ecb6e894bbe044669ce093271b244c5b61f58c 100644 (file)
@@ -67,10 +67,7 @@ public class SequenceDefinition2Test {
         structDef = new StructDefinition(structDec, null, "x",  new Definition[] { new IntegerDefinition(id, null, lengthName, seqLen) });
 
         SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
-        ByteBuffer allocateDirect = java.nio.ByteBuffer.allocateDirect(seqLen * len);
-        if( allocateDirect == null){
-            throw new IllegalStateException("Failed to allocate memory");
-        }
+        ByteBuffer allocateDirect = ByteBuffer.allocateDirect(seqLen * len);
         BitBuffer input = new BitBuffer(allocateDirect);
         for (int i = 0; i < seqLen; i++) {
             input.putInt(i);
index 701672c8303d8b09b127f859eda7c2305777bc91..641a54156163648bc97a8dab34271cbf81cf66e5 100644 (file)
@@ -82,9 +82,6 @@ public class StringDeclarationTest {
         IDefinitionScope definitionScope = null;
         String fieldName = "id";
         ByteBuffer allocate = ByteBuffer.allocate(100);
-        if (allocate == null) {
-            throw new IllegalStateException("Failed to allocate memory");
-        }
         BitBuffer bb = new BitBuffer(allocate);
         StringDefinition result = fixture.createDefinition(definitionScope,
                 fieldName, bb);
index ed77cbe5ed719edbc2acbe42a6efaad9309d4f76..ec87f9f4f270e7b6f9030047af6da59bfe9888c1 100644 (file)
@@ -48,9 +48,6 @@ public class StringDefinitionTest {
         String name = "testString";
         StringDeclaration stringDec = StringDeclaration.getStringDeclaration(Encoding.UTF8);
         ByteBuffer byteBuffer = ByteBuffer.allocate(100);
-        if (byteBuffer == null) {
-            throw new IllegalStateException("Failed to allocate memory");
-        }
         BitBuffer bb = new BitBuffer(byteBuffer);
         byteBuffer.mark();
         testString = new String("testString");
index ce8d5149f673ef0c11f231b8a519958d84d6883a..ed966b63fc1faafdb4cc18337981f28a6c9264b9 100644 (file)
@@ -82,9 +82,6 @@ public class StructDeclarationTest {
     public void testCreateDefinition() throws CTFException {
         String fieldName = "";
         ByteBuffer allocate = ByteBuffer.allocate(100);
-        if (allocate == null) {
-            throw new IllegalStateException("Failed to allocate memory");
-        }
         BitBuffer bb = new BitBuffer(allocate);
         StructDefinition result = fixture.createDefinition(null, fieldName, bb);
         assertNotNull(result);
index 9b99cf0bd84e2975be811c03a57a811beb6e388f..5de6e62ef3836f50cded11edecebed01c5adbc41 100644 (file)
@@ -139,9 +139,6 @@ public class VariantDeclarationTest {
         IDefinitionScope definitionScope = createDefinitionScope();
         String fieldName = "";
         ByteBuffer allocate = ByteBuffer.allocate(100);
-        if (allocate == null) {
-            throw new IllegalStateException("Failed to allocate memory");
-        }
         BitBuffer bb = new BitBuffer(allocate);
         VariantDefinition result = fixture.createDefinition(definitionScope, fieldName, bb);
 
index aa3646058daa7bf46701e0396ef136fd2fcf39be..37f3fd7efef8daf709390e26082f12e50924721c 100644 (file)
@@ -15,8 +15,6 @@
 
 package org.eclipse.tracecompass.ctf.core.event.io;
 
-import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
-
 import java.nio.BufferUnderflowException;
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
@@ -64,7 +62,7 @@ public final class BitBuffer {
      * Default constructor, makes a big-endian buffer
      */
     public BitBuffer() {
-        this(checkNotNull(ByteBuffer.allocateDirect(0)), ByteOrder.BIG_ENDIAN);
+        this(ByteBuffer.allocateDirect(0), ByteOrder.BIG_ENDIAN);
     }
 
     /**
index 3a87c31169cfc44425b0ce549d4803f4d34442a4..2f64df9fc59990928b85e15c4c2b62a136293cda 100644 (file)
@@ -95,10 +95,8 @@ public class EthernetIIPacket extends Packet {
             byte[] array = new byte[packet.array().length - packet.position()];
             packet.get(array);
             ByteBuffer payload = ByteBuffer.wrap(array);
-            if (payload != null) {
-                payload.order(ByteOrder.BIG_ENDIAN);
-                payload.position(0);
-            }
+            payload.order(ByteOrder.BIG_ENDIAN);
+            payload.position(0);
             fPayload = payload;
 
         } else {
This page took 0.031449 seconds and 5 git commands to generate.