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 2022/03/28 07:06:44 UTC

[GitHub] [dubbo] tiger822 opened a new issue #9847: org.apache.dubbo.metadata.definition.builder.MapTypeBuilder#build写死actualTypeArgsLength==2??

tiger822 opened a new issue #9847:
URL: https://github.com/apache/dubbo/issues/9847


   
   ### Environment
   
   * Dubbo version: 3.0.3
   * Operating System version: windows10
   * Java version: 11
   
   ### Steps to reproduce this issue
   
   1. 我定义了一个返回类型 ResponseEntity
      public class ResponseEntity<T> extends LinkedHashMap<String,Object> implements Serializable {...}
      @Override
     public ResponseEntity<String> 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
   
   <!-- What do you expect from the above steps?-->
   
   ### Actual Behavior
   
   <!-- What actually happens? -->
   
   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)
   


-- 
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] wangchengming666 edited a comment on issue #9847: org.apache.dubbo.metadata.definition.builder.MapTypeBuilder#build写死actualTypeArgsLength==2??

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


   翻了以前的一些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 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] tiger822 edited a comment on issue #9847: org.apache.dubbo.metadata.definition.builder.MapTypeBuilder#build写死actualTypeArgsLength==2??

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


   单目或3目的就有问题,如下
   
   `
   @Data
   @NoArgsConstructor
   @AllArgsConstructor
   public class ResponseEntity<T> extends LinkedHashMap<String,Object> implements Serializable {
     private long id;
     private int errCode;
     private String message;
     private T result;
     public static <V> ResponseEntity<V> fromResult(long id, V val){
       ResponseEntity<V> 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;
     }
   }
   
   `


-- 
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] chickenlj closed issue #9847: org.apache.dubbo.metadata.definition.builder.MapTypeBuilder#build写死actualTypeArgsLength==2??

Posted by GitBox <gi...@apache.org>.
chickenlj closed issue #9847:
URL: https://github.com/apache/dubbo/issues/9847


   


-- 
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] tiger822 edited a comment on issue #9847: org.apache.dubbo.metadata.definition.builder.MapTypeBuilder#build写死actualTypeArgsLength==2??

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


   单目或3目的就有问题,如下
   `
   @Data
   @NoArgsConstructor
   @AllArgsConstructor
   public class ResponseEntity<T> extends LinkedHashMap<String,Object> implements Serializable {
     private long id;
     private int errCode;
     private String message;
     private T result;
     public static <V> ResponseEntity<V> fromResult(long id, V val){
       ResponseEntity<V> 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;
     }
   }
   `


-- 
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] wangchengming666 commented on issue #9847: org.apache.dubbo.metadata.definition.builder.MapTypeBuilder#build写死actualTypeArgsLength==2??

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


   翻了以前的一些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 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] tiger822 commented on issue #9847: org.apache.dubbo.metadata.definition.builder.MapTypeBuilder#build写死actualTypeArgsLength==2??

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


   解决了, https://blog.csdn.net/rocklee/article/details/123796775


-- 
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] tiger822 commented on issue #9847: org.apache.dubbo.metadata.definition.builder.MapTypeBuilder#build写死actualTypeArgsLength==2??

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


   单目或3目的就有问题,如下
   @Data
   @NoArgsConstructor
   @AllArgsConstructor
   public class ResponseEntity<T> extends LinkedHashMap<String,Object> implements Serializable {
     private long id;
     private int errCode;
     private String message;
     private T result;
     public static <V> ResponseEntity<V> fromResult(long id, V val){
       ResponseEntity<V> 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;
     }
   }


-- 
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] tiger822 commented on issue #9847: org.apache.dubbo.metadata.definition.builder.MapTypeBuilder#build写死actualTypeArgsLength==2??

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


   硬要改为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;
     }
   }
   
   `


-- 
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] tiger822 commented on issue #9847: org.apache.dubbo.metadata.definition.builder.MapTypeBuilder#build写死actualTypeArgsLength==2??

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


   第一次遇见阿里产品里面响应这么快的,给你666个赞,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