Skip to content

Api use inner static class will throw javassist.NotFoundException #1242

@johnyannj

Description

@johnyannj

demo:

@RestSchema(schemaId="demo")
class Service
{
    public static class Model
    {

    }

    @RequestMapping(path = "/get", method = RequestMethod.GET)
    public Model foo()
    {
        return null;
    }
}

it will take error at

org.apache.servicecomb.common.javassist.CtType.(CtType.java:55)

  public CtType(JavaType javaType) {
    if (CtTypeJavaType.class.isInstance(javaType)) {
      CtType ctType = ((CtTypeJavaType) javaType).getType();
      init(ctType.ctClass, ctType.hasGenericTypes, ctType.genericSignature);
      return;
    }

    ClassLoader classLoader = javaType.getRawClass().getClassLoader();
    try {
      ClassPool classPool = JavassistUtils.getOrCreateClassPool(classLoader);
      **init(classPool.get(javaType.getRawClass().getCanonicalName()), javaType.hasGenericTypes(),
          javaType.getGenericSignature()**
      );
    } catch (NotFoundException e) {
      throw new IllegalStateException(
          String.format("Failed to get CtClass for %s in classloader %s.",
              javaType.getRawClass().getName(),
              classLoader),
          e);
    }
}

javaType.getRawClass().getCanonicalName() is "com.zhaoyanblog.Service.Model"
the classPool.get will throw javassist.NotFoundException
the right name is "com.zhaoyanblog.Service$Model"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions