Skip to content

Commit

Permalink
Don't raise unchecked exception for unknown Optional Parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Thorvardarson committed Feb 25, 2012
1 parent 08a95b5 commit 24eec00
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
2 changes: 1 addition & 1 deletion jsmpp/src/main/java/org/jsmpp/bean/OptionalParameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
6 changes: 2 additions & 4 deletions jsmpp/src/main/java/org/jsmpp/bean/OptionalParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
16 changes: 3 additions & 13 deletions jsmpp/src/test/java/org/jsmpp/bean/OptionalParameterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 24eec00

Please sign in to comment.