java: change spec. of pack methods in several template classes as follow: If user passes null object to the pack method, MessageTypeException is thrown.

This commit is contained in:
Muga Nishizawa 2010-12-12 00:46:05 +09:00
parent f936a307c6
commit 419d2e9564
9 changed files with 46 additions and 11 deletions

View File

@ -25,7 +25,11 @@ public class BigIntegerTemplate implements Template {
private BigIntegerTemplate() { } private BigIntegerTemplate() { }
public void pack(Packer pk, Object target) throws IOException { public void pack(Packer pk, Object target) throws IOException {
pk.packBigInteger((BigInteger)target); try {
pk.packBigInteger((BigInteger)target);
} catch (NullPointerException e) {
throw new MessageTypeException("target is null.", e);
}
} }
public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException { public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException {

View File

@ -24,7 +24,11 @@ public class BooleanTemplate implements Template {
private BooleanTemplate() { } private BooleanTemplate() { }
public void pack(Packer pk, Object target) throws IOException { public void pack(Packer pk, Object target) throws IOException {
pk.packBoolean((Boolean)target); try {
pk.packBoolean((Boolean)target);
} catch (NullPointerException e) {
throw new MessageTypeException("target is null.", e);
}
} }
public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException { public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException {

View File

@ -24,7 +24,11 @@ public class ByteArrayTemplate implements Template {
private ByteArrayTemplate() { } private ByteArrayTemplate() { }
public void pack(Packer pk, Object target) throws IOException { public void pack(Packer pk, Object target) throws IOException {
pk.packByteArray((byte[])target); try {
pk.packByteArray((byte[])target);
} catch (NullPointerException e) {
throw new MessageTypeException("target is null.", e);
}
} }
public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException { public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException {

View File

@ -26,11 +26,14 @@ public class ByteBufferTemplate implements Template {
} }
public void pack(Packer pk, Object target) throws IOException { public void pack(Packer pk, Object target) throws IOException {
pk.pack((ByteBuffer) target); try {
pk.packByteBuffer((ByteBuffer) target);
} catch (NullPointerException e) {
throw new MessageTypeException("target is null.", e);
}
} }
public Object unpack(Unpacker pac, Object to) throws IOException, public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException {
MessageTypeException {
return pac.unpackByteBuffer(); return pac.unpackByteBuffer();
} }

View File

@ -24,7 +24,11 @@ public class DoubleTemplate implements Template {
private DoubleTemplate() { } private DoubleTemplate() { }
public void pack(Packer pk, Object target) throws IOException { public void pack(Packer pk, Object target) throws IOException {
pk.packDouble(((Double)target)); try {
pk.packDouble(((Double)target));
} catch (NullPointerException e) {
throw new MessageTypeException("target is null.", e);
}
} }
public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException { public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException {

View File

@ -24,7 +24,11 @@ public class FloatTemplate implements Template {
private FloatTemplate() { } private FloatTemplate() { }
public void pack(Packer pk, Object target) throws IOException { public void pack(Packer pk, Object target) throws IOException {
pk.packFloat((Float)target); try {
pk.packFloat((Float)target);
} catch (NullPointerException e) {
throw new MessageTypeException("target is null.", e);
}
} }
public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException { public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException {

View File

@ -24,7 +24,11 @@ public class IntegerTemplate implements Template {
private IntegerTemplate() { } private IntegerTemplate() { }
public void pack(Packer pk, Object target) throws IOException { public void pack(Packer pk, Object target) throws IOException {
pk.packInt((Integer)target); try {
pk.packInt((Integer)target);
} catch (NullPointerException e) {
throw new MessageTypeException("target is null.", e);
}
} }
public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException { public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException {

View File

@ -24,7 +24,11 @@ public class LongTemplate implements Template {
private LongTemplate() { } private LongTemplate() { }
public void pack(Packer pk, Object target) throws IOException { public void pack(Packer pk, Object target) throws IOException {
pk.packLong((Long)target); try {
pk.packLong((Long)target);
} catch (NullPointerException e) {
throw new MessageTypeException("target is null.", e);
}
} }
public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException { public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException {

View File

@ -24,7 +24,11 @@ public class StringTemplate implements Template {
private StringTemplate() { } private StringTemplate() { }
public void pack(Packer pk, Object target) throws IOException { public void pack(Packer pk, Object target) throws IOException {
pk.packString((String)target); try {
pk.packString((String)target);
} catch (NullPointerException e) {
throw new MessageTypeException("target is null.", e);
}
} }
public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException { public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException {