diff --git a/jsmpp/src/main/java/org/jsmpp/bean/OptionalParameter.java b/jsmpp/src/main/java/org/jsmpp/bean/OptionalParameter.java index 2c3aca5..faa2f60 100644 --- a/jsmpp/src/main/java/org/jsmpp/bean/OptionalParameter.java +++ b/jsmpp/src/main/java/org/jsmpp/bean/OptionalParameter.java @@ -305,7 +305,7 @@ public static Tag valueOf(short code) { if (tag.code == code) return tag; } - throw new IllegalArgumentException("No tag for: " + code); + return null; } } diff --git a/jsmpp/src/main/java/org/jsmpp/bean/OptionalParameters.java b/jsmpp/src/main/java/org/jsmpp/bean/OptionalParameters.java index 411b95d..5f1cf94 100644 --- a/jsmpp/src/main/java/org/jsmpp/bean/OptionalParameters.java +++ b/jsmpp/src/main/java/org/jsmpp/bean/OptionalParameters.java @@ -100,10 +100,8 @@ public static OptionalParameter.Byte newSarTotalSegments(int value) { * @return the OptionalParameter object. */ public static OptionalParameter deserialize(short tagCode, byte[] content) { - Tag tag = null; - try { - tag = Tag.valueOf(tagCode); - } catch (IllegalArgumentException e) { + Tag tag = Tag.valueOf(tagCode); + if(tag == null) { return new COctetString(tagCode, content); } diff --git a/jsmpp/src/test/java/org/jsmpp/bean/OptionalParameterTest.java b/jsmpp/src/test/java/org/jsmpp/bean/OptionalParameterTest.java index 04f9c47..b483a9c 100644 --- a/jsmpp/src/test/java/org/jsmpp/bean/OptionalParameterTest.java +++ b/jsmpp/src/test/java/org/jsmpp/bean/OptionalParameterTest.java @@ -16,7 +16,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; +import static org.testng.Assert.assertNull; import org.jsmpp.bean.OptionalParameter.OctetString; import org.jsmpp.bean.OptionalParameter.Tag; @@ -53,23 +53,13 @@ public void stringParameterDeserialization() { @Test public void undefinedTag() { final short tagCode = 0x0000; - try { - Tag.valueOf(tagCode); - fail("Tag code 0x0000 should be not found"); - } catch (IllegalArgumentException e) { - } - OptionalParameters.deserialize(tagCode, "Undefined tag".getBytes()); + assertNull(Tag.valueOf(tagCode)); } @Test public void anotherUndefinedTag() { short tagCode = (short)(-127 & 0xffff); - try { - Tag.valueOf(tagCode); - fail("Tag code " + tagCode + " should be not found"); - } catch (IllegalArgumentException e) { - } - OptionalParameters.deserialize(tagCode, "Undefined tag".getBytes()); + assertNull(Tag.valueOf(tagCode)); } @Test