You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@eagle.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2019/05/08 03:51:00 UTC

[jira] [Work logged] (EAGLE-1096) getJSONArray may cause exception, optJSONArray should be used

     [ https://issues.apache.org/jira/browse/EAGLE-1096?focusedWorklogId=238970&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-238970 ]

ASF GitHub Bot logged work on EAGLE-1096:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 08/May/19 03:50
            Start Date: 08/May/19 03:50
    Worklog Time Spent: 10m 
      Work Description: qingwen220 commented on pull request #1001: [EAGLE-1096] getJSONArray may cause exception, optJSONArray can be used
URL: https://github.com/apache/eagle/pull/1001#discussion_r281904704
 
 

 ##########
 File path: eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/utils/JMXQueryHelper.java
 ##########
 @@ -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();
 
 Review comment:
   Agree with @jhsenjaliya,  this change will incur the NPE issue. 
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 238970)
    Time Spent: 0.5h  (was: 20m)

> getJSONArray may cause exception, optJSONArray should be used
> -------------------------------------------------------------
>
>                 Key: EAGLE-1096
>                 URL: https://issues.apache.org/jira/browse/EAGLE-1096
>             Project: Eagle
>          Issue Type: Bug
>            Reporter: bd2019us
>            Priority: Major
>         Attachments: 1.patch
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> Hello,
> The method call jsonBeansObject.getJSONArray("beans")  may throw JSONException when the key does not exist, which will crash the program. To ensure safety, optJSONArray is recommended to use, which will avoid the exception in case no such key.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)