You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/07/03 09:34:02 UTC

[GitHub] [dubbo] wilddragon opened a new issue #8212: Dubbo 2.7.8及以上判断Map类型的逻辑有误

wilddragon opened a new issue #8212:
URL: https://github.com/apache/dubbo/issues/8212


   - [ ] I have searched the [issues](https://github.com/apache/dubbo/issues) of this repository and believe that this is not a duplicate.
   - [ ] I have checked the [FAQ](https://github.com/apache/dubbo/blob/master/FAQ.md) of this repository and believe that this is not a duplicate.
   
   ### Environment
   
   * Dubbo version: 2.7.8
   * Operating System version: Windows/Linux
   * Java version: 8u292
   
   ### Steps to reproduce this issue
   
   1. 创建一个HashMap的子类作为返回类型,但是只有一个泛型参数< T >,继承时HashMap泛型参数填<String,Object>
   class Abc< Str > extends HashMap<String,Object>{
      ....
   }
   这种用法很常见
   2. 在dubbo编译成功后,运行时会报错,[ServiceDefinitionBuilder] Map type [{0}] with unexpected amount of arguments [{1}].
   3. 此问题毕现。
   MapTypeBuilder.java此处代码建议修改如下:
   即:先判断此类是否实现了Map接口或其子接口,如果实现了,则必须要求有两个泛型参数
          否则,需要检查其父类,并将其父类的泛型参数加入到Cache中来。
           if (actualTypeArgsLength != 2) {
               for (Class<?> c : clazz.getInterfaces()){
                   if (Map.class.isAssignableFrom(c)){
                       throw new IllegalArgumentException(MessageFormat.format(
                               "[ServiceDefinitionBuilder] Map type [{0}] with unexpected amount of arguments [{1}]."
                                       + Arrays.toString(actualTypeArgs), type, actualTypeArgs));
                   }
               }
           }
           boolean checkSuper = true;
           for (Class<?> c : clazz.getInterfaces()){
               if (Map.class.isAssignableFrom(c)){
                   checkSuper = false;
                   break;
               }
           }
           if (checkSuper) {
               Class<?> cl = clazz.getSuperclass();
               Type t = clazz.getGenericSuperclass();
               build(t, cl, typeCache);
           }
   
   
   Pls. provide [GitHub address] to reproduce this issue.
   
   ### Expected Result
   
   What do you expected from the above steps?
   
   ### Actual Result
   
   What actually happens?
   
   If there is an exception, please attach the exception trace:
   
   ```
   Just put your stack trace here!
   ```
   


-- 
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] wilddragon commented on issue #8212: Dubbo 2.7.8及以上判断Map类型的逻辑有误

Posted by GitBox <gi...@apache.org>.
wilddragon commented on issue #8212:
URL: https://github.com/apache/dubbo/issues/8212#issuecomment-873803017


   this is a dubbo-demo, please put it to dubbo project directory.
   then compile and  run  dubbo-demo-annotation-provider-2.7.8.jar, you will reproduce it.
   https://github.com/wilddragon/dubbo-demo


-- 
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] xul0038 edited a comment on issue #8212: Dubbo 2.7.8及以上判断Map类型的逻辑有误

Posted by GitBox <gi...@apache.org>.
xul0038 edited a comment on issue #8212:
URL: https://github.com/apache/dubbo/issues/8212#issuecomment-888308919


   1.创建自定义TypeBuilder
   ```
   package com.xxx.dubbo.TreeBuilder;
   
   public class TreeBuilder implements TypeBuilder , Prioritized {
   
       @Override
       public boolean accept(Type type, Class<?> clazz) {
           if (clazz == null) {
               return false;
           }
           return Tree.class.isAssignableFrom(clazz);
       }
   
       @Override
       public int getPriority() {
           return -1;
       }
   
       @Override
       public TypeDefinition build(Type type, Class<?> clazz, Map<Class<?>, TypeDefinition> typeCache) {
           // balabala...
       }
   }
   ```
   2. `META-INF`下创建`dubbo/internal/org.apache.dubbo.metadata.definition.builder.TypeBuilder`文件
   ```
   tree=com.xxx.dubbo.TreeBuilder
   ```
   #6306


-- 
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] horizonzy commented on issue #8212: Dubbo 2.7.8及以上判断Map类型的逻辑有误

Posted by GitBox <gi...@apache.org>.
horizonzy commented on issue #8212:
URL: https://github.com/apache/dubbo/issues/8212#issuecomment-873810203


   We will see it later, thanks.


-- 
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] horizonzy commented on issue #8212: Dubbo 2.7.8及以上判断Map类型的逻辑有误

Posted by GitBox <gi...@apache.org>.
horizonzy commented on issue #8212:
URL: https://github.com/apache/dubbo/issues/8212#issuecomment-873386106


   Hi, how can we reproduce it, could you provide a demo help to reproduce it, thanks.


-- 
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] xul0038 commented on issue #8212: Dubbo 2.7.8及以上判断Map类型的逻辑有误

Posted by GitBox <gi...@apache.org>.
xul0038 commented on issue #8212:
URL: https://github.com/apache/dubbo/issues/8212#issuecomment-888308919


   1.创建自定义TypeBuilder
   ```
   public class TreeBuilder implements TypeBuilder , Prioritized {
   
       @Override
       public boolean accept(Type type, Class<?> clazz) {
           if (clazz == null) {
               return false;
           }
           return Tree.class.isAssignableFrom(clazz);
       }
   
       @Override
       public int getPriority() {
           return -1;
       }
   
       @Override
       public TypeDefinition build(Type type, Class<?> clazz, Map<Class<?>, TypeDefinition> typeCache) {
           // balabala...
       }
   }
   ```
   2. `META-INF`下创建`dubbo/internal/org.apache.dubbo.metadata.definition.builder.TypeBuilder`文件
   
   #6306


-- 
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] wilddragon commented on issue #8212: Dubbo 2.7.8及以上判断Map类型的逻辑有误

Posted by GitBox <gi...@apache.org>.
wilddragon commented on issue #8212:
URL: https://github.com/apache/dubbo/issues/8212#issuecomment-873801039


   https://github.com/wilddragon/dubbo-demo


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