关于启动时MapTypeBuilder写死判断参数长度为2的问题
- Dominant language
- Java
- Stars
- 41.6k
- Forks
- 26.4k
- Avg merge
- 15h 13m
- Merged PRs (30d)
- 4
Description
- [x] I have searched the [issues](https://github.com/apache/dubbo/issues) of this repository and believe that this is not a duplicate.
- [x] 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.3
* Operating System version: linux
* Java version: 1.8
### Steps to reproduce this issue
1. MapTypeBuilder 中写死map泛型参数数目必须为2,导致在使用外部开源的原生类型的map判断报错。
```java
@Override
public TypeDefinition build(Type type, Class clazz, Map, TypeDefinition> typeCache) {
if (!(type instanceof ParameterizedType)) {
return new TypeDefinition(clazz.getName());
}
ParameterizedType parameterizedType = (ParameterizedType) type;
Type[] actualTypeArgs = parameterizedType.getActualTypeArguments();
if (actualTypeArgs == null || actualTypeArgs.length != 2) {
throw new IllegalArgumentException(MessageFormat.format(
"[ServiceDefinitionBuilder] Map type [{0}] with unexpected amount of arguments [{1}]." + actualTypeArgs,
new Object[] {type, actualTypeArgs}));
}
for (Type actualType : actualTypeArgs) {
if (actualType instanceof ParameterizedType) {
// Nested collection or map.
Class rawType = (Class) ((ParameterizedType) actualType).getRawType();
TypeDefinitionBuilder.build(actualType, rawType, typeCache);
} else if (actualType instanceof Class) {
Class actualClass = (Class) actualType;
if (actualClass.isArray() || actualClass.isEnum()) {
TypeDefinitionBuilder.build(null, actualClass, typeCache);
} else {
DefaultTypeBuilder.build(actualClass, typeCache);
}
}
}
```
如下所示,参数长度为1。
```java
package it.unimi.dsi.fastutil.ints;
public interface Int2ObjectMap extends Int2ObjectFunction, Map {}
```
该类来自于
```
it.unimi.dsi
fastutil
```
### Expected Result
~~是否可以判断他的上层实现来进行判断~~
能否定义一个order接口,然后sort一下,这样外部拓展的时候可以手动调准新增的builder的顺序
Contributor guide
Research direction
Start at the MapTypeBuilder.build implementation shown in the issue and reproduce startup processing with fastutil's Int2ObjectMap. Trace how its generic arguments are inspected and compare that behavior with ordinary Map types. Done means the external map type no longer fails during startup while existing map handling remains valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100