Guard against NPEs on conversion of null values
This commit is contained in:
@@ -70,7 +70,7 @@ abstract public class JedisConverters extends Converters {
|
||||
TUPLE_SET_TO_TUPLE_SET = new SetConverter<redis.clients.jedis.Tuple, Tuple>(
|
||||
new Converter<redis.clients.jedis.Tuple, Tuple>() {
|
||||
public Tuple convert(redis.clients.jedis.Tuple source) {
|
||||
return new DefaultTuple(source.getBinaryElement(), source.getScore());
|
||||
return source != null ? new DefaultTuple(source.getBinaryElement(), source.getScore()) : null;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -64,7 +64,7 @@ abstract public class LettuceConverters extends Converters {
|
||||
static {
|
||||
DATE_TO_LONG = new Converter<Date, Long>() {
|
||||
public Long convert(Date source) {
|
||||
return source.getTime();
|
||||
return source != null ? source.getTime() : null;
|
||||
}
|
||||
|
||||
};
|
||||
@@ -104,7 +104,7 @@ abstract public class LettuceConverters extends Converters {
|
||||
};
|
||||
SCORED_VALUE_TO_TUPLE = new Converter<ScoredValue<byte[]>, Tuple>() {
|
||||
public Tuple convert(ScoredValue<byte[]> source) {
|
||||
return new DefaultTuple(source.value, Double.valueOf(source.score));
|
||||
return source != null ? new DefaultTuple(source.value, Double.valueOf(source.score)) : null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -85,12 +85,12 @@ abstract public class SrpConverters extends Converters {
|
||||
};
|
||||
REPLIES_TO_BYTES_SET = new Converter<Reply[], Set<byte[]>>() {
|
||||
public Set<byte[]> convert(Reply[] source) {
|
||||
return new LinkedHashSet<byte[]>(SrpConverters.toBytesList(source));
|
||||
return source != null ? new LinkedHashSet<byte[]>(SrpConverters.toBytesList(source)) : null;
|
||||
}
|
||||
};
|
||||
BYTES_TO_PROPERTIES = new Converter<byte[], Properties>() {
|
||||
public Properties convert(byte[] source) {
|
||||
return SrpConverters.toProperties(new String(source, Charsets.UTF_8));
|
||||
return source != null ? SrpConverters.toProperties(new String(source, Charsets.UTF_8)) : null;
|
||||
}
|
||||
};
|
||||
BYTES_TO_DOUBLE = new Converter<byte[], Double>() {
|
||||
@@ -101,6 +101,9 @@ abstract public class SrpConverters extends Converters {
|
||||
};
|
||||
REPLIES_TO_TUPLE_SET = new Converter<Reply[], Set<Tuple>>() {
|
||||
public Set<Tuple> convert(Reply[] byteArrays) {
|
||||
if(byteArrays == null) {
|
||||
return null;
|
||||
}
|
||||
Set<Tuple> tuples = new LinkedHashSet<Tuple>(byteArrays.length / 2 + 1);
|
||||
for (int i = 0; i < byteArrays.length; i++) {
|
||||
byte[] value = (byte[]) byteArrays[i].data();
|
||||
@@ -113,6 +116,9 @@ abstract public class SrpConverters extends Converters {
|
||||
};
|
||||
REPLIES_TO_BYTES_MAP = new Converter<Reply[], Map<byte[], byte[]>>() {
|
||||
public Map<byte[], byte[]> convert(Reply[] byteArrays) {
|
||||
if(byteArrays == null) {
|
||||
return null;
|
||||
}
|
||||
Map<byte[], byte[]> map = new LinkedHashMap<byte[], byte[]>(byteArrays.length / 2);
|
||||
for (int i = 0; i < byteArrays.length; i++) {
|
||||
map.put((byte[]) byteArrays[i++].data(), (byte[]) byteArrays[i].data());
|
||||
@@ -122,11 +128,14 @@ abstract public class SrpConverters extends Converters {
|
||||
};
|
||||
BYTES_TO_STRING = new Converter<byte[], String>() {
|
||||
public String convert(byte[] data) {
|
||||
return new String((byte[]) data, Charsets.UTF_8);
|
||||
return data != null ? new String((byte[]) data, Charsets.UTF_8) : null;
|
||||
}
|
||||
};
|
||||
REPLIES_TO_BOOLEAN_LIST = new Converter<Reply[], List<Boolean>>() {
|
||||
public List<Boolean> convert(Reply[] source) {
|
||||
if(source == null) {
|
||||
return null;
|
||||
}
|
||||
List<Boolean> results = new ArrayList<Boolean>();
|
||||
for (Reply r : source) {
|
||||
results.add(SrpConverters.toBoolean(((IntegerReply) r).data()));
|
||||
@@ -136,6 +145,9 @@ abstract public class SrpConverters extends Converters {
|
||||
};
|
||||
REPLIES_TO_STRING_LIST = new Converter<Reply[], List<String>>() {
|
||||
public List<String> convert(Reply[] source) {
|
||||
if(source == null) {
|
||||
return null;
|
||||
}
|
||||
List<String> results = new ArrayList<String>();
|
||||
for (Reply r : source) {
|
||||
results.add(SrpConverters.toString((byte[]) r.data()));
|
||||
|
||||
Reference in New Issue
Block a user