Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dubbo 2.7.8及以上判断Map类型的逻辑有误 #8212

Open
2 tasks
wilddragon opened this issue Jul 3, 2021 · 5 comments
Open
2 tasks

Dubbo 2.7.8及以上判断Map类型的逻辑有误 #8212

wilddragon opened this issue Jul 3, 2021 · 5 comments

Comments

@wilddragon
Copy link

  • I have searched the issues of this repository and believe that this is not a duplicate.
  • I have checked the FAQ 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!
@horizonzy
Copy link
Member

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

@wilddragon
Copy link
Author

@wilddragon
Copy link
Author

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

@horizonzy
Copy link
Member

We will see it later, thanks.

@xul0038
Copy link

xul0038 commented Jul 28, 2021

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...
    }
}
  1. META-INF下创建dubbo/internal/org.apache.dubbo.metadata.definition.builder.TypeBuilder文件
tree=com.xxx.dubbo.TreeBuilder

#6306

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants