java: throws MessagePackException if target==null on *ArrayTemplate

This commit is contained in:
FURUHASHI Sadayuki 2010-12-13 18:52:25 +09:00
parent aff964c58b
commit 339725f73d
9 changed files with 43 additions and 8 deletions

View File

@ -28,7 +28,11 @@ public class BooleanArrayTemplate implements Template {
throw new MessageTypeException(); throw new MessageTypeException();
} }
boolean[] array = (boolean[])target; boolean[] array = (boolean[])target;
pk.packArray(array.length); try {
pk.packArray(array.length);
} catch (NullPointerException e) {
throw new MessageTypeException("target is null.", e);
}
for(boolean a : array) { for(boolean a : array) {
pk.pack(a); pk.pack(a);
} }

View File

@ -24,7 +24,11 @@ public class ByteTemplate implements Template {
private ByteTemplate() { } private ByteTemplate() { }
public void pack(Packer pk, Object target) throws IOException { public void pack(Packer pk, Object target) throws IOException {
pk.packByte((Byte)target); try {
pk.packByte((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

@ -42,6 +42,9 @@ public class DefaultTemplate implements Template {
public void pack(Packer pk, Object target) throws IOException { public void pack(Packer pk, Object target) throws IOException {
if(messagePackable) { if(messagePackable) {
if(target == null) {
throw new MessageTypeException("target is null.");
}
((MessagePackable)target).messagePack(pk); ((MessagePackable)target).messagePack(pk);
return; return;
} }

View File

@ -28,7 +28,11 @@ public class DoubleArrayTemplate implements Template {
throw new MessageTypeException(); throw new MessageTypeException();
} }
double[] array = (double[])target; double[] array = (double[])target;
pk.packArray(array.length); try {
pk.packArray(array.length);
} catch (NullPointerException e) {
throw new MessageTypeException("target is null.", e);
}
for(double a : array) { for(double a : array) {
pk.pack(a); pk.pack(a);
} }

View File

@ -28,7 +28,11 @@ public class FloatArrayTemplate implements Template {
throw new MessageTypeException(); throw new MessageTypeException();
} }
float[] array = (float[])target; float[] array = (float[])target;
pk.packArray(array.length); try {
pk.packArray(array.length);
} catch (NullPointerException e) {
throw new MessageTypeException("target is null.", e);
}
for(float a : array) { for(float a : array) {
pk.pack(a); pk.pack(a);
} }

View File

@ -28,7 +28,11 @@ public class IntArrayTemplate implements Template {
throw new MessageTypeException(); throw new MessageTypeException();
} }
int[] array = (int[])target; int[] array = (int[])target;
pk.packArray(array.length); try {
pk.packArray(array.length);
} catch (NullPointerException e) {
throw new MessageTypeException("target is null.", e);
}
for(int a : array) { for(int a : array) {
pk.pack(a); pk.pack(a);
} }

View File

@ -28,7 +28,11 @@ public class LongArrayTemplate implements Template {
throw new MessageTypeException(); throw new MessageTypeException();
} }
long[] array = (long[])target; long[] array = (long[])target;
pk.packArray(array.length); try {
pk.packArray(array.length);
} catch (NullPointerException e) {
throw new MessageTypeException("target is null.", e);
}
for(long a : array) { for(long a : array) {
pk.pack(a); pk.pack(a);
} }

View File

@ -28,7 +28,11 @@ public class ShortArrayTemplate implements Template {
throw new MessageTypeException(); throw new MessageTypeException();
} }
short[] array = (short[])target; short[] array = (short[])target;
pk.packArray(array.length); try {
pk.packArray(array.length);
} catch (NullPointerException e) {
throw new MessageTypeException("target is null.", e);
}
for(short a : array) { for(short a : array) {
pk.pack(a); pk.pack(a);
} }

View File

@ -24,7 +24,11 @@ public class ShortTemplate implements Template {
private ShortTemplate() { } private ShortTemplate() { }
public void pack(Packer pk, Object target) throws IOException { public void pack(Packer pk, Object target) throws IOException {
pk.packShort((Short)target); try {
pk.packShort((Short)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 {