From 6fbc2ff748635d764f64378d3fbb503253ec5ff4 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Wed, 4 Mar 2015 11:13:51 -0500 Subject: [PATCH] ctf: Don't throw runtime exceptions on invalid IntegerDeclaration attributes 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 Reviewed-on: https://git.eclipse.org/r/43173 Reviewed-by: Hudson CI Reviewed-by: Matthew Khouzam Tested-by: Matthew Khouzam --- .../tests/types/IntegerDeclarationTest.java | 28 ------------------- .../core/event/types/IntegerDeclaration.java | 4 --- .../ctf/core/event/metadata/IOStructGen.java | 4 +-- 3 files changed, 2 insertions(+), 34 deletions(-) diff --git a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/IntegerDeclarationTest.java b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/IntegerDeclarationTest.java index e15d68a9c7..7f1f79eca6 100644 --- a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/IntegerDeclarationTest.java +++ b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/IntegerDeclarationTest.java @@ -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 diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IntegerDeclaration.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IntegerDeclaration.java index 740ccd441b..8dfec6457d 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IntegerDeclaration.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IntegerDeclaration.java @@ -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; diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/metadata/IOStructGen.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/metadata/IOStructGen.java index 4f3f4e2984..3861a1542b 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/metadata/IOStructGen.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/metadata/IOStructGen.java @@ -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) { -- 2.34.1