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

Conversation

bd2019us
Copy link

@bd2019us bd2019us commented Apr 14, 2019

Be sure to do all of the following to help us incorporate your contribution
quickly and easily:

  • Make sure the PR title is formatted like:
    [EAGLE-<Jira issue #>] Description of pull request
  • Make sure tests pass via mvn clean verify. (Even better, enable
    Travis-CI on your fork and ensure the whole test matrix passes).
  • Replace <Jira issue #> in the title with the actual Jira issue
    number, if there is one.
  • If this contribution is large, please file an Apache
    Individual Contributor License Agreement.

@@ -56,7 +56,7 @@
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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants