确实是误判为 bug 的报告用例 1
src/main/java/zuo/biao/apijson/server/AbstractSQLConfig.java: 897 (可信度: 65%)
zuo.biao.apijson.server.AbstractSQLConfig.putWhere(String, Object, boolean)中
AbstractSQLConfig.combine 可能的空指针解引用
对应实际文件
https://github.com/APIJSON/APIJSON/blob/d8cfc9e6be87bd6116ecf8a125a52021f0154761/APIJSON-Java-Server/APIJSONLibrary/src/main/java/zuo/biao/apijson/server/AbstractSQLConfig.java
内方法
@Override
public AbstractSQLConfig putWhere(String key, Object value, boolean prior) {
if (key != null) {
if (where == null) {
where = new LinkedHashMap<String, Object>();
}
where.put(key, value);
combine = getCombine();
List<String> andList = combine == null ? null : combine.get("&");
if (value == null) {
andList.remove(key);
}
else if (andList == null || andList.contains(key) == false) {
int i = 0;
if (andList == null) {
andList = new ArrayList<>();
}
else if (prior && andList.isEmpty() == false) {
if (andList.contains(KEY_ID)) {
i ++;
}
if (andList.contains(KEY_ID_IN)) {
i ++;
}
if (andList.contains(KEY_USER_ID)) {
i ++;
}
if (andList.contains(KEY_USER_ID_IN)) {
i ++;
}
}
if (prior) {
andList.add(i, key); //userId的优先级不能比id高 0, key);
} else {
andList.add(key); //AbstractSQLExecutor.onPutColumn里getSQL,要保证缓存的SQL和查询的SQL里 where 的 key:value 顺序一致
}
}
combine.put("&", andList);
}
return this;
}
实际上在前面已经用
combine = getCombine();
做了处理,return 的值不会是 null
@NotNull
@Override
public Map<String, List<String>> getCombine() {
List<String> andList = combine == null ? null : combine.get("&");
if (andList == null) {
andList = where == null ? new ArrayList<String>() : new ArrayList<String>(where.keySet());
if (combine == null) {
combine = new HashMap<>();
}
combine.put("&", andList);
}
return combine;
}
确实是误判为 bug 的报告用例 2
src/main/java/zuo/biao/apijson/JSONObject.java: 411 (可信度: 95%)
1 这里比较了 clazz 和 null,说明 clazz 可能为空指针
2 调用 clazz 的 java.lang.Class.getName 方法(使用可疑的空指针)
对应实际文件
https://github.com/APIJSON/APIJSON/blob/d8cfc9e6be87bd6116ecf8a125a52021f0154761/APIJSON-Java-Server/APIJSONLibrary/src/main/java/zuo/biao/apijson/JSONObject.java
内方法
/**put and return value
* @param key StringUtil.isEmpty(key, true) ? key = value.getClass().getSimpleName();
* @param value
* @return value
*/
@Override
public Object put(String key, Object value) {
if (value == null) {
Log.e(TAG, "put value == null >> return null;");
return null;
}
if (StringUtil.isEmpty(key, true)) {
Class<?> clazz = value.getClass();
if (clazz == null || clazz.getAnnotation(MethodAccess.class) == null) {
throw new IllegalArgumentException("puts StringUtil.isNotEmpty(key, true) == false" +
" && clazz == null || clazz.getAnnotation(MethodAccess.class) == null" +
" \n key为空时仅支持 类型被@MethodAccess注解 的value !!!" +
" \n 如果一定要这么用,请对 " + clazz.getName() + " 注解!" +
" \n 如果是类似 key[]:{} 结构的请求,建议用 putsAll(...) !");
}
key = value.getClass().getSimpleName();
}
return super.put(key, value);
}
406 行
Class<?> clazz = value.getClass();
Class 是对象声明后就有的,到执行这行前 value 已经判断过,又不会为 null,
所以实际上 clazz 不会为 null,407 行
if (clazz == null || clazz.getAnnotation(MethodAccess.class) == null) {
中 clazz == null 是一个冗余的判断,后面删掉了,实际上 411 行
clazz.getName()
永远不会因为 clazz == null 而导致 throw NullPointerException,
所以这也是一个误判为 bug 的用例。
确实是误判为 bug 的报告用例 3
严重 空指针解引用 src/main/java/zuo/biao/apijson/server/AbstractSQLConfig.java:844 (可信度 50%)
对应实际文件
https://github.com/Tencent/APIJSON/blob/d8cfc9e6be87bd6116ecf8a125a52021f0154761/APIJSON-Java-Server/APIJSONLibrary/src/main/java/zuo/biao/apijson/server/AbstractSQLConfig.java
内方法
/**
* @param key
* @param exactMatch
* @return
*/
@JSONField(serialize = false)
@Override
public Object getWhere(String key, boolean exactMatch) {
if (exactMatch) {
return where == null ? null : where.get(key);
}
Set<String> set = key == null || where == null ? null : where.keySet();
if (set != null) {
synchronized (where) {
if (where != null) {
int index;
for (String k : set) {
index = k.indexOf(key);
if (index >= 0 && StringUtil.isName(k.substring(index)) == false) {
return where.get(k);
}
}
}
}
}
return null;
}
843 行已经用 set != null 来判断,而根据 842 行代码,where 为 null 时 set 必定为 null,
永远不会因为 where == null 而导致 throw NullPointerException,
所以这也是一个误判为 bug 的用例。