mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-04-01 09:24:51 +02:00
java: change spec. of pack methods in ListTemplate and MapTemplate as follow: If user passes null object to the pack method, MessageTypeException is thrown.
This commit is contained in:
parent
419d2e9564
commit
0c07e745f8
@ -38,7 +38,10 @@ public class ListTemplate implements Template {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void pack(Packer pk, Object target) throws IOException {
|
||||
if (! (target instanceof List)) {
|
||||
throw new MessageTypeException();
|
||||
if (target == null) {
|
||||
throw new MessageTypeException(new NullPointerException("target is null."));
|
||||
}
|
||||
throw new MessageTypeException("target is not List type: " + target.getClass());
|
||||
}
|
||||
List<Object> list = (List<Object>)target;
|
||||
pk.packArray(list.size());
|
||||
@ -47,6 +50,7 @@ public class ListTemplate implements Template {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException {
|
||||
int length = pac.unpackArray();
|
||||
List<Object> list;
|
||||
@ -62,6 +66,7 @@ public class ListTemplate implements Template {
|
||||
return list;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object convert(MessagePackObject from, Object to) throws MessageTypeException {
|
||||
MessagePackObject[] array = from.asArray();
|
||||
List<Object> list;
|
||||
|
@ -44,7 +44,10 @@ public class MapTemplate implements Template {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void pack(Packer pk, Object target) throws IOException {
|
||||
if(!(target instanceof Map)) {
|
||||
throw new MessageTypeException();
|
||||
if (target == null) {
|
||||
throw new MessageTypeException(new NullPointerException("target is null."));
|
||||
}
|
||||
throw new MessageTypeException("target is not Map type: " + target.getClass());
|
||||
}
|
||||
Map<Object,Object> map = (Map<Object,Object>) target;
|
||||
pk.packMap(map.size());
|
||||
@ -54,6 +57,7 @@ public class MapTemplate implements Template {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException {
|
||||
int length = pac.unpackMap();
|
||||
Map<Object,Object> map;
|
||||
|
Loading…
x
Reference in New Issue
Block a user