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

Exception getting generics in completabilefuture when using api doc #211

Open
SpicyQuark opened this issue Jun 1, 2023 · 0 comments
Open

Comments

@SpicyQuark
Copy link

SpicyQuark commented Jun 1, 2023

there are some warnings when running application.

It seems like DubboApiDocsAnnotationScanner cant handle the parameter's class which extends generic parent.

For example com.alibaba.fastjson2.JSONObject

public interface ITestDubboService {
  public String call(name, JSONObject params);
}
import com.alibaba.fastjson2.JSONObject;
import org.apache.dubbo.apidocs.annotations.ApiDoc;
import org.apache.dubbo.apidocs.annotations.ApiModule;
import org.apache.dubbo.apidocs.annotations.RequestParam;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance;

@DubboService(
    timeout = 3000,
    loadbalance = RoundRobinLoadBalance.NAME)
@ApiModule(value = "dubbo测试接口", apiInterface = ITestDubboService.class)
public class TestDubboServiceImpl implements ITestDubboService {

  @ApiDoc(
      value = "call",
      description = "方法调用测试",
      responseClassDescription = "json字串")
  @Override
  public String call(
          @RequestParam(value = "name", description = "调用者") String name,
          @RequestParam(value = "params", description = "参数列表") JSONObject params) {
      System.out.println(name+" calls "+params);
  }
}
DubboApiDocsAnnotationScanner#processApiDocAnnotation(...) {
...
        String key = String.format("%s.%s%s", moduleAnn.apiInterface().getCanonicalName(), method.getName(), desc);
        DubboApiDocsCache.addApiParamsAndResp(key, apiParamsAndResp);

        Class<?>[] argsClass = method.getParameterTypes();
        Annotation[][] argsAnns = method.getParameterAnnotations();
        Parameter[] parameters = method.getParameters();
        Type[] parametersTypes = method.getGenericParameterTypes();
        List<ApiParamsCacheItem> paramList = new ArrayList<>(argsClass.length);
...
        for (int i = 0; i < argsClass.length; i++) {
            Class<?> argClass = argsClass[i];
            Type parameterType = parametersTypes[i];
            methodParamInfoSb.append(METHOD_PARAM_INDEX_BOUNDARY_LEFT).append(i)
                    .append(METHOD_PARAM_INDEX_BOUNDARY_RIGHT).append(argClass.getCanonicalName());
            if (i + 1 < argsClass.length) {
                methodParamInfoSb.append(METHOD_PARAMETER_SEPARATOR);
            }
...
}
java.lang.ClassNotFoundException: V
	at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[?:?]
	at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[?:?]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?]
	at java.lang.Class.forName0(Native Method) ~[?:?]
	at java.lang.Class.forName(Class.java:375) ~[?:?]
	at org.apache.dubbo.apidocs.utils.ClassTypeUtil.makeClass(ClassTypeUtil.java:407) ~[dubbo-api-docs-core-2.7.8.3.jar:2.7.8.3]
	at org.apache.dubbo.apidocs.utils.ClassTypeUtil.initClassTypeWithDefaultValueNoProceeField(ClassTypeUtil.java:294) ~[dubbo-api-docs-core-2.7.8.3.jar:2.7.8.3]
	at org.apache.dubbo.apidocs.utils.ClassTypeUtil.initClassTypeWithDefaultValue(ClassTypeUtil.java:145) ~[dubbo-api-docs-core-2.7.8.3.jar:2.7.8.3]
	at org.apache.dubbo.apidocs.utils.ClassTypeUtil.initClassTypeWithDefaultValue(ClassTypeUtil.java:122) ~[dubbo-api-docs-core-2.7.8.3.jar:2.7.8.3]
	at org.apache.dubbo.apidocs.core.DubboApiDocsAnnotationScanner.processField(DubboApiDocsAnnotationScanner.java:359) ~[dubbo-api-docs-core-2.7.8.3.jar:2.7.8.3]
	at org.apache.dubbo.apidocs.core.DubboApiDocsAnnotationScanner.processApiDocAnnotation(DubboApiDocsAnnotationScanner.java:282) ~[dubbo-api-docs-core-2.7.8.3.jar:2.7.8.3]
	at org.apache.dubbo.apidocs.core.DubboApiDocsAnnotationScanner.lambda$onApplicationEvent$2(DubboApiDocsAnnotationScanner.java:166) ~[dubbo-api-docs-core-2.7.8.3.jar:2.7.8.3]
	at java.util.LinkedHashMap.forEach(LinkedHashMap.java:721) ~[?:?]
	at org.apache.dubbo.apidocs.core.DubboApiDocsAnnotationScanner.onApplicationEvent(DubboApiDocsAnnotationScanner.java:113) ~[dubbo-api-docs-core-2.7.8.3.jar:2.7.8.3]
	at org.apache.dubbo.apidocs.core.DubboApiDocsAnnotationScanner.onApplicationEvent(DubboApiDocsAnnotationScanner.java:84) ~[dubbo-api-docs-core-2.7.8.3.jar:2.7.8.3]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.21.jar:5.3.21]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.21.jar:5.3.21]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.21.jar:5.3.21]
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) ~[spring-context-5.3.21.jar:5.3.21]
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) ~[spring-context-5.3.21.jar:5.3.21]
	at org.springframework.boot.context.event.EventPublishingRunListener.ready(EventPublishingRunListener.java:114) ~[spring-boot-2.7.1.jar:2.7.1]
	at org.springframework.boot.SpringApplicationRunListeners.lambda$ready$6(SpringApplicationRunListeners.java:82) ~[spring-boot-2.7.1.jar:2.7.1]
	at java.util.ArrayList.forEach(ArrayList.java:1511) [?:?]
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120) [spring-boot-2.7.1.jar:2.7.1]
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:114) [spring-boot-2.7.1.jar:2.7.1]
	at org.springframework.boot.SpringApplicationRunListeners.ready(SpringApplicationRunListeners.java:82) [spring-boot-2.7.1.jar:2.7.1]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:323) [spring-boot-2.7.1.jar:2.7.1]
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

1 participant