Skip to content

Commit

Permalink
fix bug: NPE when empty RefList value
Browse files Browse the repository at this point in the history
  • Loading branch information
xbwen committed May 20, 2020
1 parent 6f29d4c commit 4c97d83
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 12 additions & 1 deletion bugu-mongo-core/src/main/java/com/bugull/mongo/BuguMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ else if(DataType.isQueueType(type)){

private static Object fetchArrayValue(Object val, Field field, Class elementClass) {
int len = Array.getLength(val);
if(len == 0){
return null;
}
elementClass = FieldUtil.getRealType(elementClass, field);
Object arr = Array.newInstance(elementClass, len);
List<String> idList = new ArrayList<>();
Expand Down Expand Up @@ -246,6 +249,9 @@ private static Object fetchArrayValue(Object val, Field field, Class elementClas

private static List fetchCollectionValue(Object val, Field field, Class elementClass){
Collection<BuguEntity> collection = (Collection<BuguEntity>)val;
if(collection.isEmpty()){
return null;
}
List<String> idList = new ArrayList<>();
for(BuguEntity ent : collection){
if(ent != null){
Expand All @@ -267,6 +273,11 @@ private static List fetchCollectionValue(Object val, Field field, Class elementC
}

private static Map fetchMapValue(Object val, Field field) {
Map map = (Map)val;
if(map.isEmpty()){
return null;
}

//for Map<K,V>, first to check the type of V
ParameterizedType paramType = (ParameterizedType)field.getGenericType();
Type[] types = paramType.getActualTypeArguments();
Expand Down Expand Up @@ -294,8 +305,8 @@ private static Map fetchMapValue(Object val, Field field) {
isSingle = true;
}
}

//get value by different type of V
Map map = (Map)val;
Map result = new HashMap();
Class<?> cls = null;
InternalDao dao = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ private void processRefList(BuguEntity entity, Field f){
if(clazz == null){
return;
}
InternalDao dao = DaoCache.getInstance().get(clazz);
BuguQuery query = dao.query().in(Operator.ID, idList);
dao.remove(query);
if(idList != null && !idList.isEmpty()){
InternalDao dao = DaoCache.getInstance().get(clazz);
BuguQuery query = dao.query().in(Operator.ID, idList);
dao.remove(query);
}
}

private List<String> getArrayIds(Object value){
Expand Down

0 comments on commit 4c97d83

Please sign in to comment.