ctf: Don't throw runtime exceptions on invalid IntegerDeclaration attributes
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 4 Mar 2015 16:13:51 +0000 (11:13 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 5 Mar 2015 20:53:22 +0000 (15:53 -0500)
Instead of an IllegalArgumentException, we can check earlier in IOStructGen
if the arguments we are about to pass are valid, along with the other
existing checks.

While at it, remove the check to forbid signed integers to have a size greater
than 1. 1-bit-signed is a valid representation, see Bug 457951.

Change-Id: Idb26e362973104e709b1d613783077ab56b41b94
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/43173
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/IntegerDeclarationTest.java
org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IntegerDeclaration.java
org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/metadata/IOStructGen.java

index e15d68a9c73392ee715a23015d73169719e43ac2..7f1f79eca6817035115a60a6b57161c233d07c7a 100644 (file)
@@ -69,34 +69,6 @@ public class IntegerDeclarationTest {
         assertEquals(false, result.isSigned());
     }
 
-    /**
-     * Test that IntegerDeclaration throws when constructing a signed 1 bit
-     * declaration
-     */
-    @Test(expected = java.lang.IllegalArgumentException.class)
-    public void testIntegerDeclarationIllegalArgSignedBit() {
-        int len = 1;
-        boolean signed = true;
-        int base = 1;
-        ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
-        Encoding encoding = Encoding.ASCII;
-        IntegerDeclaration.createDeclaration(len, signed, base, byteOrder, encoding, "", 16);
-    }
-
-    /**
-     * Test that IntegerDeclaration throws when constructing a invalid length
-     * declaration
-     */
-    @Test(expected = java.lang.IllegalArgumentException.class)
-    public void testIntegerDeclarationIllegalArgBadLenght() {
-        int len = 0;
-        boolean signed = false;
-        int base = 1;
-        ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
-        Encoding encoding = Encoding.ASCII;
-        IntegerDeclaration.createDeclaration(len, signed, base, byteOrder, encoding, "", 16);
-    }
-
     /**
      * Test the factory part more rigorously to make sure there are no
      * regressions
index 740ccd441b371b289a6ff97bd001b6c55bf9b5de..8dfec6457d4897f9c90557315651fb81f8038429 100644 (file)
@@ -240,10 +240,6 @@ public final class IntegerDeclaration extends Declaration implements ISimpleData
      */
     private IntegerDeclaration(int len, boolean signed, int base,
             @Nullable ByteOrder byteOrder, Encoding encoding, String clock, long alignment) {
-        if (len <= 0 || len == 1 && signed) {
-            throw new IllegalArgumentException();
-        }
-
         fLength = len;
         fSigned = signed;
         fBase = base;
index 4f3f4e29847ac7d267fd25b80d1945836320c884..3861a1542b6ce4d919f8256025fbfc7d73e60a9d 100644 (file)
@@ -1433,8 +1433,8 @@ public class IOStructGen {
             }
         }
 
-        if (size == 0) {
-            throw new ParseException("Integer missing size attribute"); //$NON-NLS-1$
+        if (size <= 0) {
+            throw new ParseException("Invalid size attribute in Integer: " + size); //$NON-NLS-1$
         }
 
         if (alignment == 0) {
This page took 0.028653 seconds and 5 git commands to generate.