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

org.apache.dubbo.metadata.definition.builder.MapTypeBuilder#build写死actualTypeArgsLength==2?? #9847

Closed
tiger822 opened this issue Mar 28, 2022 · 5 comments · Fixed by #9849
Labels
type/bug Bugs to being fixed
Milestone

Comments

@tiger822
Copy link

Environment

  • Dubbo version: 3.0.3
  • Operating System version: windows10
  • Java version: 11

Steps to reproduce this issue

  1. 我定义了一个返回类型 ResponseEntity
    public class ResponseEntity extends LinkedHashMap<String,Object> implements Serializable {...}
    @OverRide
    public ResponseEntity sayHello(String a) {
    return ResponseEntity.fromResult(0,a);
    }
    那么启动时会报错,org.apache.dubbo.metadata.definition.builder.MapTypeBuilder#build,if (actualTypeArgsLength != 2) {。。。}
    不明白为什么要写死
    2.如果我将ResponseEntity改为2目:
    public class ResponseEntity<T,Object> extends LinkedHashMap<String,Object> implements Serializable {...}
    @OverRide
    public ResponseEntity<String,Object> sayHello(String a) {
    return ResponseEntity.fromResult(0,a);
    }
    ...这样就可以,这算是一个bug么? 我看21年的时候有人提出过,但新版本也没改善。

Expected Behavior

Actual Behavior

If there is an exception, please attach the exception trace:

Just put your stack trace here!

Caused by: java.lang.IllegalArgumentException: [ServiceDefinitionBuilder] Map type [com.freestyle.common.models.ResponseEntity<java.lang.String>] with unexpected amount of arguments [[Ljava.lang.reflect.Type;@3c1f2651].[class java.lang.String]
	at org.apache.dubbo.metadata.definition.builder.MapTypeBuilder.build(MapTypeBuilder.java:56)
	at org.apache.dubbo.metadata.definition.TypeDefinitionBuilder.build(TypeDefinitionBuilder.java:56)
	at org.apache.dubbo.metadata.definition.TypeDefinitionBuilder.build(TypeDefinitionBuilder.java:80)
@tiger822 tiger822 added the type/bug Bugs to being fixed label Mar 28, 2022
@tiger822
Copy link
Author

tiger822 commented Mar 28, 2022

单目或3目的就有问题,如下

`
@DaTa
@NoArgsConstructor
@AllArgsConstructor
public class ResponseEntity extends LinkedHashMap<String,Object> implements Serializable {
private long id;
private int errCode;
private String message;
private T result;
public static ResponseEntity fromResult(long id, V val){
ResponseEntity ret = new ResponseEntity<>();
ret.result = val;
ret.id=id;
return ret;
}
public static ResponseEntity fromErr(long id, int errCode, String message){
ResponseEntity ret=new ResponseEntity(id,errCode,message,null);
return ret;
}
@JsonIgnore
public Map toMap(){
Map map= JsonUtils.fromJson(JsonUtils.toJsonString(this), HashMap.class);
return map;
}
}

`

@tiger822
Copy link
Author

硬要改为2目的就没问题
`
@DaTa
@NoArgsConstructor
@AllArgsConstructor
public class ResponseEntity<V,T> extends LinkedHashMap<String,V> implements Serializable {
private long id;
private int errCode;
private String message;
private T result;
public static <V,T> ResponseEntity<V,T> fromResult(long id, T val){
ResponseEntity<V,T> ret = new ResponseEntity<>();
ret.result = val;
ret.id=id;
return ret;
}
public static <V,T>ResponseEntity<V,T> fromErr(long id, int errCode, String message){
ResponseEntity<V,T> ret=new ResponseEntity<>(id,errCode,message,(T)null);
return ret;
}
@JsonIgnore
public Map toMap(){
Map map= JsonUtils.fromJson(JsonUtils.toJsonString(this), HashMap.class);
return map;
}
}

`

@tiger822
Copy link
Author

@wangchengming666
Copy link
Member

wangchengming666 commented Mar 29, 2022

翻了以前的一些issue 比如 #8212#5122 都提到过这个问题,我认为这段强校验的代码没必要存在。

        if (actualTypeArgsLength != 2) {
            throw new IllegalArgumentException(MessageFormat.format(
                    "[ServiceDefinitionBuilder] Map type [{0}] with unexpected amount of arguments [{1}]."
                            + Arrays.toString(actualTypeArgs), type, actualTypeArgs));
        }

虽然可以通过SPI来扩展,但是还是给用户带来了一定的困扰。

This was referenced Mar 29, 2022
@chickenlj chickenlj added this to the 3.0.8 milestone Mar 30, 2022
@tiger822
Copy link
Author

第一次遇见阿里产品里面响应这么快的,给你666个赞,thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Bugs to being fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants