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

在Spring Boot中运行Dubbo消费端报错frozen class (cannot edit) #796

Closed
rong1981 opened this issue Oct 31, 2017 · 3 comments
Closed
Labels
type/bug Bugs to being fixed
Milestone

Comments

@rong1981
Copy link

问题描述

使用Spring Boot构建web app,Controller中通过dubbo消费端远程调用服务端,使用注解进行参数校验,如getName(@NotNull String id)。
在调用过程中始终报错:

java.lang.RuntimeException: XXXService_GetNameParameter: frozen class (cannot edit)
at javassist.ClassPool.checkNotFrozen(ClassPool.java:617) ~[javassist-3.21.0-GA.jar:?]
at javassist.ClassPool.makeClass(ClassPool.java:859) ~[javassist-3.21.0-GA.jar:?]
at javassist.ClassPool.makeClass(ClassPool.java:836) ~[javassist-3.21.0-GA.jar:?]
at com.alibaba.dubbo.validation.support.jvalidation.JValidator.getMethodParameterBean(JValidator.java:166)

问题分析

  1. 初步判断和dubbo版本无关,应该是一个bug。报错的原因是再次尝试查找动态生成的类时,应该能找到,实际上因为classloader的原因无法找到。即com.alibaba.dubbo.validation.support.jvalidation.JValidator第163行:
    parameterClass = (Class<?>) Class.forName(parameterClassName, true, clazz.getClassLoader());
    这里应该能够找到parameterClass,而不是再次抛出ClassNotFoundException。
  2. 出现ClassNotFoundException的原因,是由于在生成参数类XXXService_GetNameParameter的时候,没有传入该参数的接口的classLoader(即clazz.getClassLoader),而是使用了默认的Context ClassLoader。
  3. 建议修改JValidator第202行为:
    parameterClass = ctClass.toClass(clazz.getClassLoader(), null);传入接口的classLoader,保证其一致性。
@chickenlj chickenlj added priority/normal type/bug Bugs to being fixed labels Nov 2, 2017
@chickenlj chickenlj added this to the 2.5.8 milestone Nov 2, 2017
@chickenlj
Copy link
Contributor

赞,应该是要使用clazz.getClassLoader()保持一致性

@luryson
Copy link
Contributor

luryson commented May 30, 2019

#3796

应该是同一个地方的问题,我觉得不仅是classloader的问题,这里还有线程安全问题

@TonyZiCheng
Copy link

这点有个疑问:”出现ClassNotFoundException的原因,是由于在生成参数类XXXService_GetNameParameter的时候,没有传入该参数的接口的classLoader“,什么情况下没有传入改参数接口的calssLoader,而是使用默认classLoader

rolandhe pushed a commit to rolandhe/dubbo that referenced this issue Sep 9, 2019
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

No branches or pull requests

4 participants