You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "YAGAMIL (via GitHub)" <gi...@apache.org> on 2023/05/19 06:46:36 UTC

[GitHub] [dubbo] YAGAMIL opened a new issue, #12350: org.apache.dubbo.config.spring.util.DubboAnnotationUtils#convertParameters中当参数列表未空时,直接返回了不可修改的Collections.emptyMap(),我认为不合适

YAGAMIL opened a new issue, #12350:
URL: https://github.com/apache/dubbo/issues/12350

   <!-- If you need to report a security issue please visit https://github.com/apache/dubbo/security/policy -->
   
   - [ ] I have searched the [issues](https://github.com/apache/dubbo/issues) of this repository and believe that this is not a duplicate.
   - [ ] I have searched the [release notes](https://github.com/apache/dubbo/releases) of this repository and believe that this is not a duplicate.
   
   ## Describe the feature
   <!-- Please also discuss possible business value -->
   org.apache.dubbo.config.spring.util.DubboAnnotationUtils#convertParameters中当参数列表未空时,直接返回了不可修改的Collections.emptyMap(),我认为不合适
   
   
   `java
       public static Map<String, String> convertParameters(String[] parameters) {
           if (ArrayUtils.isEmpty(parameters)) {
               return Collections.emptyMap();
           }
   
           List<String> compatibleParameterArray = Arrays.stream(parameters)
               .map(String::trim)
               .reduce(new ArrayList<>(parameters.length), (list, parameter) ->
                   {
                       if (list.size() % 2 == 1) {
                           //value doesn't split
                           list.add(parameter);
                           return list;
                       }
   
                       String[] sp1 = parameter.split(":");
                       if (sp1.length > 0 && sp1.length % 2 == 0) {
                           //key split
                           list.addAll(Arrays.stream(sp1).map(String::trim).collect(Collectors.toList()));
                           return list;
                       }
                       sp1 = parameter.split("=");
                       if (sp1.length > 0 && sp1.length % 2 == 0) {
                           list.addAll(Arrays.stream(sp1).map(String::trim).collect(Collectors.toList()));
                           return list;
                       }
                       list.add(parameter);
                       return list;
                   }
                   , (a, b) -> a);
   
           return CollectionUtils.toStringMap(compatibleParameterArray.toArray(new String[0]));
       }
   `
   内部服务适配过程中发现会对这个属性做put操作,但当@DubboService设置parameters为空时,返回了一个不可扩展的Map,这时候会抛出相关异常,我认为这里既然已经是空map,那么可不可编辑影响不大,应该返回空的HashMap<>


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

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] AlbumenJ closed issue #12350: org.apache.dubbo.config.spring.util.DubboAnnotationUtils#convertParameters中当参数列表未空时,直接返回了不可修改的Collections.emptyMap(),我认为不合适

Posted by "AlbumenJ (via GitHub)" <gi...@apache.org>.
AlbumenJ closed issue #12350: org.apache.dubbo.config.spring.util.DubboAnnotationUtils#convertParameters中当参数列表未空时,直接返回了不可修改的Collections.emptyMap(),我认为不合适
URL: https://github.com/apache/dubbo/issues/12350


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

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] 24kpure commented on issue #12350: org.apache.dubbo.config.spring.util.DubboAnnotationUtils#convertParameters中当参数列表未空时,直接返回了不可修改的Collections.emptyMap(),我认为不合适

Posted by "24kpure (via GitHub)" <gi...@apache.org>.
24kpure commented on issue #12350:
URL: https://github.com/apache/dubbo/issues/12350#issuecomment-1567678015

   如果却有需求,可以提PR改一下,我这没其它补充


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

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] 24kpure commented on issue #12350: org.apache.dubbo.config.spring.util.DubboAnnotationUtils#convertParameters中当参数列表未空时,直接返回了不可修改的Collections.emptyMap(),我认为不合适

Posted by "24kpure (via GitHub)" <gi...@apache.org>.
24kpure commented on issue #12350:
URL: https://github.com/apache/dubbo/issues/12350#issuecomment-1566803252

   抱歉给您带来的困扰,我是这段代码的作者,聊聊个人想法
   1.空Map倾向于使用Collections.emptyMap(),更优雅,性能的角度也更好,潜在缺点是不可编辑。这个场景是解析注解的参数,所以返回不可编辑的map也可以被认为是合理的。
   2.您的业务场景是什么?如果需要修改parameter属性,建议在配置中心加载前处理,尽可能前置,在流程中改注解配置可能会带来其它意想不到的问题?


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

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] YAGAMIL commented on issue #12350: org.apache.dubbo.config.spring.util.DubboAnnotationUtils#convertParameters中当参数列表未空时,直接返回了不可修改的Collections.emptyMap(),我认为不合适

Posted by "YAGAMIL (via GitHub)" <gi...@apache.org>.
YAGAMIL commented on issue #12350:
URL: https://github.com/apache/dubbo/issues/12350#issuecomment-1566933783

   > 抱歉给您带来的困扰,我是这段代码的作者,聊聊个人想法 1.空Map倾向于使用Collections.emptyMap(),更优雅,性能的角度也更好,潜在缺点是不可编辑。这个场景是解析注解的参数,所以返回不可编辑的map也可以被认为是合理的。 2.您的业务场景是什么?如果需要修改参数属性,建议在配置中心加载前处理,尽可能前置,在流程中改注解配置可能会带来其它意想不到的问题?
   
   实际上这个问题是我在阿里内部整合dubbo和hsf才出现的问题,hsf会在启动后往内部put一个新的hession参数来进行扩展,这时候如果对应的service编写的时候没有生命额外的paramters,那么就会抛出不可修改异常,因为是阿里内部的问题,所以我觉得不便明说,其次我感觉这个性能和优雅带来的特点可能也比较小,仅此而已


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

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org