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();
}
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) {
pk.pack(a);
}

View File

@ -24,7 +24,11 @@ public class ByteTemplate implements Template {
private ByteTemplate() { }
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 {

View File

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

View File

@ -28,7 +28,11 @@ public class DoubleArrayTemplate implements Template {
throw new MessageTypeException();
}
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) {
pk.pack(a);
}

View File

@ -28,7 +28,11 @@ public class FloatArrayTemplate implements Template {
throw new MessageTypeException();
}
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) {
pk.pack(a);
}

View File

@ -28,7 +28,11 @@ public class IntArrayTemplate implements Template {
throw new MessageTypeException();
}
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) {
pk.pack(a);
}

View File

@ -28,7 +28,11 @@ public class LongArrayTemplate implements Template {
throw new MessageTypeException();
}
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) {
pk.pack(a);
}

View File

@ -28,7 +28,11 @@ public class ShortArrayTemplate implements Template {
throw new MessageTypeException();
}
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) {
pk.pack(a);
}

View File

@ -24,7 +24,11 @@ public class ShortTemplate implements Template {
private ShortTemplate() { }
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 {