You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2020/07/06 02:17:32 UTC

[GitHub] [skywalking] zoumingzm opened a new issue #5036: @Tag returnedObject bug

zoumingzm opened a new issue #5036:
URL: https://github.com/apache/skywalking/issues/5036


   Please answer these questions before submitting your issue.
   
   - Why do you submit this issue?
   - [ ] Bug  
   ___
   ### Bug
   - Which version of SkyWalking, OS and JRE?
   7.0.0
   
   - Which company or project?
   powersi.com    
   
   - What happen?
   If possible, provide a way for reproducing the error. e.g. demo application, component version.
   Only nomal object is supported.  
   List, Array, Map is not supported.  
   ___
   ### Requirement or improvement
   - Please describe about your requirements or improvement suggestions.  
   Preparation returnContext and usage returnContext are inconsistent needs to be fixed.
   --
   example:
   return List or Array :  returnedObject.['key'] or returnedObject.key. or returnedObject.key.fieldName
   return Map: returnedObject.['key'] or returnedObject.key. 
   --
   before fix:
   ```
       public static Map<String, Object> evaluationReturnContext(Object ret)  {
           Map<String, Object> context = new HashMap<>();
           Field[] fields = ret.getClass().getDeclaredFields();
           for (Field field : fields) {
               field.setAccessible(true);
               try {
                   context.put(field.getName(), field.get(ret));
               } catch (Exception e) {
                   logger.debug("evaluationReturnContext error, ret is {}, exception is {}", ret, e.getMessage());
               }
           }
           return context;
       }
   ```
   --
   after fix:
   ```
       public static Map<String, Object> evaluationReturnContext(Object ret)  {
           Map<String, Object> context = new HashMap<>();
           if (ret != null){
               if (ret instanceof List) {
                   List retList = (List) ret;
                   int retLength = retList.size();
                   for (int i = 0; i < retLength; i++) {
                       context.put(String.valueOf(i), retList.get(i));
                   }
               } else if (ret.getClass().isArray()) {
                   int length = Array.getLength(ret);
                   for (int i = 0; i < length; i++) {
                       context.put(String.valueOf(i), Array.get(ret, i));
                   }
               } else if (ret instanceof Map) {
                   context.putAll((Map) ret);
               } else {
                   Field[] fields = ret.getClass().getDeclaredFields();
                   for (Field field : fields) {
                       field.setAccessible(true);
                       try {
                           context.put(field.getName(), field.get(ret));
                       } catch (Exception e) {
                           logger.debug("evaluationReturnContext error, ret is {}, exception is {}", ret, e.getMessage());
                       }
                   }
               }
           }
           return context;
       }
   ```
   
   - Test
   return value:
   Map: {"username":"张三", "age":18, "info": "username=张三&age=18"}
   List: [{"username":"张三", "age":18, "info": "username=张三&age=18"}]
   Array:["张三","18","username=张三&age=18"]
   --
   before fix context alue:
   Map: {UNTREEIFY_THRESHOLD=6, TREEIFY_THRESHOLD=8, entrySet=null, DEFAULT_LOAD_FACTOR=0.75, threshold=3, DEFAULT_INITIAL_CAPACITY=16, modCount=3, serialVersionUID=362498820763181265, size=3, loadFactor=0.75, MAXIMUM_CAPACITY=1073741824, MIN_TREEIFY_CAPACITY=64, table=[Ljava.util.HashMap$Node;@54d18072}
   List: {a=[Lorg.apache.skywalking.apm.toolkit.activation.trace.TagAnnotationTest$User;@45e37a7e, serialVersionUID=-2764017481108945198}
   Array: empty
   Obviously, this is not what we want。
   --
   after fix context value: 
   Map:  {"username":"张三", "age":18, "info": "username=张三&age=18"}
   List:  {"0", {"username":"张三", "age":18, "info": "username=张三&age=18"}}
   Array:  {"0":"张三", "1":"18", "2":"username=张三&age=18"}
   it's right.
   
   


----------------------------------------------------------------
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



[GitHub] [skywalking] zoumingzm commented on issue #5036: @Tag returnedObject bug

Posted by GitBox <gi...@apache.org>.
zoumingzm commented on issue #5036:
URL: https://github.com/apache/skywalking/issues/5036#issuecomment-653985650


   > Could you send a pull request with tests for this fix? It would be more clear than this.
   
   ok, I'll try later.


----------------------------------------------------------------
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



[GitHub] [skywalking] wu-sheng commented on issue #5036: @Tag returnedObject bug

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #5036:
URL: https://github.com/apache/skywalking/issues/5036#issuecomment-653982725


   Could you send a pull request with tests for this fix? It would be more clear than this.


----------------------------------------------------------------
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



[GitHub] [skywalking] kezhenxu94 closed issue #5036: @Tag returnedObject bug

Posted by GitBox <gi...@apache.org>.
kezhenxu94 closed issue #5036:
URL: https://github.com/apache/skywalking/issues/5036


   


----------------------------------------------------------------
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