Skip to content

Commit b973f3e

Browse files
committed
优化代码:预防 NPE,减少重复执行逻辑
1 parent 6a5764d commit b973f3e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,19 @@ public AbstractObjectParser parse(String name, boolean isReuse) throws Exception
249249
break;
250250
}
251251

252-
Object value = entry.getValue();
252+
String key = entry == null ? null : entry.getKey();
253+
Object value = key == null ? null : entry.getValue();
253254
if (value == null) {
254255
continue;
255256
}
256-
String key = entry.getKey();
257-
257+
258258
// 处理url crud, 将crud 转换为真实method
259259
RequestMethod _method = this.parser.getRealMethod(method, key, value);
260-
// 没有执行校验流程的情况,比如url head, sql@子查询, sql@ method=GET
261-
if (key.endsWith("@") && request.get(key) instanceof JSONObject) {
262-
request.getJSONObject(key).put(apijson.JSONObject.KEY_METHOD, GET);
260+
// 没有执行校验流程的情况,比如url head, sql@子查询, sql@ method=GET
261+
262+
Object obj = key.endsWith("@") ? request.get(key) : null;
263+
if (obj instanceof JSONObject) {
264+
((JSONObject) obj).put(apijson.JSONObject.KEY_METHOD, GET);
263265
}
264266

265267
try {

0 commit comments

Comments
 (0)