apache / apache/dubbo

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

Open
#8,212 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
41.6k
Forks
26.4k
Avg merge
15h 13m
Merged PRs (30d)
4

Description

- [ ] 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泛型参数填
class Abc< Str > extends HashMap{
....
}
这种用法很常见
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!
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.