Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

[EAGLE-1096] getJSONArray may cause exception, optJSONArray can be used #1001

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static Map<String, JMXBean> parseStream(InputStream is) {
final Map<String, JMXBean> resultMap = new HashMap<String, JMXBean>();
final JSONTokener tokener = new JSONTokener(is);
final JSONObject jsonBeansObject = new JSONObject(tokener);
final JSONArray jsonArray = jsonBeansObject.getJSONArray("beans");
final JSONArray jsonArray = jsonBeansObject.optJSONArray("beans");
int size = jsonArray.length();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if jsonArray is going to be null, can u add that handling as well ? Thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @jhsenjaliya, this change will incur the NPE issue.

for (int i = 0; i < size; ++i) {
final JSONObject obj = (JSONObject) jsonArray.get(i);
Expand Down