[ 
https://issues.apache.org/jira/browse/SCB-873?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16603793#comment-16603793
 ] 

ASF GitHub Bot commented on SCB-873:
------------------------------------

wujimin commented on a change in pull request #884: [SCB-873] Make the 
validation result display the parameter name instead of arg0, arg1
URL: 
https://github.com/apache/incubator-servicecomb-java-chassis/pull/884#discussion_r215109868
 
 

 ##########
 File path: 
swagger/swagger-invocation/invocation-validator/src/main/java/org/apache/servicecomb/swagger/invocation/validator/ParanamerParameterNameProvider.java
 ##########
 @@ -18,55 +18,41 @@
 
 import java.lang.reflect.AccessibleObject;
 import java.lang.reflect.Constructor;
+import java.lang.reflect.Executable;
 import java.lang.reflect.Method;
 import java.lang.reflect.Parameter;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
-import java.util.WeakHashMap;
-
 import javax.validation.ParameterNameProvider;
 
+import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
 import org.apache.servicecomb.swagger.generator.core.utils.ParamUtils;
 
 
 public class ParanamerParameterNameProvider implements ParameterNameProvider {
-  private final Map<AccessibleObject, List<String>> methodCache = 
makeMethodCache();
-
-  protected Map<AccessibleObject, List<String>> makeMethodCache() {
-    return Collections.synchronizedMap(new WeakHashMap<AccessibleObject, 
List<String>>());
-  }
+  private final Map<AccessibleObject, List<String>> methodCache = new 
ConcurrentHashMapEx<>();
 
   @Override
   public List<String> getParameterNames(Constructor<?> constructor) {
-    List<String> parameterNames = methodCache.get(constructor);
-    if (parameterNames == null) {
-      Parameter[] parameters = constructor.getParameters();
-      parameterNames = new ArrayList<>(parameters.length);
-
-      for (int i = 0; i < parameters.length; i++) {
-        parameterNames.add(ParamUtils.getParameterName(constructor, i));
-      }
-      methodCache.put(constructor, parameterNames);
-    }
-
+    List<String> parameterNames = methodCache.computeIfAbsent(constructor, k 
-> getParameterNamesEx(constructor));
     return Collections.unmodifiableList(parameterNames);
   }
 
   @Override
   public List<String> getParameterNames(Method method) {
-    List<String> parameterNames = methodCache.get(method);
-    if (parameterNames == null) {
-      Parameter[] parameters = method.getParameters();
-      parameterNames = new ArrayList<>(parameters.length);
+    List<String> parameterNames = methodCache.computeIfAbsent(method, k -> 
getParameterNamesEx(method));
+    return Collections.unmodifiableList(parameterNames);
+  }
 
-      for (int i = 0; i < parameters.length; i++) {
-        parameterNames.add(ParamUtils.getParameterName(method, i));
-      }
-      methodCache.put(method, parameterNames);
-    }
+  private List<String> getParameterNamesEx(Executable methodOrConstructor) {
+    Parameter[] parameters = methodOrConstructor.getParameters();
 
 Review comment:
   just invoke getParameterCount
   no need to clone a new array instance

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Make the validation result display the parameter name instead of arg0, arg1
> ---------------------------------------------------------------------------
>
>                 Key: SCB-873
>                 URL: https://issues.apache.org/jira/browse/SCB-873
>             Project: Apache ServiceComb
>          Issue Type: Improvement
>          Components: Java-Chassis
>    Affects Versions: java-chassis-1.0.0
>            Reporter: WeiChao
>            Assignee: WeiChao
>            Priority: Major
>             Fix For: java-chassis-1.1.0
>
>




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

Reply via email to