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

feat: let use of javassist compatible both under java 17 and java 1.8 #1316

Merged
merged 1 commit into from
Apr 10, 2023

Conversation

Lo1nt
Copy link
Collaborator

@Lo1nt Lo1nt commented Mar 10, 2023

Motivation:

Running com.alipay.sofa.rpc.proxy.javassist.JavassistProxyTest encounters error under jdk 17

        com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException: RPC-010080001: Construct proxy with [javassist] occurs error. 
	at com.alipay.sofa.rpc.proxy.javassist.JavassistProxy.getProxy(JavassistProxy.java:142)
	at com.alipay.sofa.rpc.proxy.javassist.JavassistProxyTest.getProxy(JavassistProxyTest.java:52)
        ......
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @17f052a3
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
	at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
	at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
	at javassist.util.proxy.SecurityActions.setAccessible(SecurityActions.java:159)
	at javassist.util.proxy.DefineClassHelper$JavaOther.defineClass(DefineClassHelper.java:213)
	at javassist.util.proxy.DefineClassHelper$Java11.defineClass(DefineClassHelper.java:52)
	at javassist.util.proxy.DefineClassHelper.toClass(DefineClassHelper.java:260)
	at javassist.ClassPool.toClass(ClassPool.java:1240)
	at javassist.ClassPool.toClass(ClassPool.java:1098)
	at javassist.ClassPool.toClass(ClassPool.java:1056)
	at javassist.CtClass.toClass(CtClass.java:1298)
	at com.alipay.sofa.rpc.proxy.javassist.JavassistProxy.getProxy(JavassistProxy.java:131)

For java 11+, if no neighbour params passed to ClassPool.toClass, the javassist.util.proxy.DefineClassHelper would make a reflection call to java.lang.ClassLoader.DefineClass, which is, however, inaccessbile from unnamed module under java 17.

Modification:

Use javassist.ClassPool#toClass(javassist.CtClass, java.lang.Class<?>, java.lang.ClassLoader, java.security.ProtectionDomain) instead of javassist.CtClass#toClass().

Result:

com.alipay.sofa.rpc.proxy.javassist.JavassistProxyTest works both under java 17 and java 1.8.

@sofastack-bot sofastack-bot bot added cla:yes CLA is ok size/S labels Mar 10, 2023
@codecov
Copy link

codecov bot commented Mar 10, 2023

Codecov Report

Merging #1316 (91b8c3b) into master (a283eb3) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##             master    #1316      +/-   ##
============================================
+ Coverage     72.02%   72.05%   +0.02%     
+ Complexity      786      784       -2     
============================================
  Files           415      415              
  Lines         17651    17653       +2     
  Branches       2753     2753              
============================================
+ Hits          12714    12720       +6     
+ Misses         3536     3532       -4     
  Partials       1401     1401              
Impacted Files Coverage Δ
...lipay/sofa/rpc/proxy/javassist/JavassistProxy.java 79.24% <100.00%> (+0.26%) ⬆️

... and 9 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@Lo1nt Lo1nt marked this pull request as ready for review March 14, 2023 02:21
Copy link
Collaborator

@EvenLjj EvenLjj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@EvenLjj EvenLjj added this to the 5.10.0 milestone Apr 10, 2023
@chuailiwu chuailiwu self-requested a review April 10, 2023 11:42
Copy link
Collaborator

@chuailiwu chuailiwu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@EvenLjj EvenLjj merged commit ec5e57f into sofastack:master Apr 10, 2023
Lo1nt added a commit that referenced this pull request Jun 20, 2023
* Modify the parsing header method to facilitate expansion (#1325)

Co-authored-by: liujianjun.ljj <liujianjun.ljj@antgroup.com>

* feat: let use of javassist compatible at jdk 17 (#1316)

Co-authored-by: junyuan <zhangminglun.zml@ant-group.com>

* upgrade rpc version to 5.10.0-SNAPSHOT (#1326)

* upgrade rpc version to 5.10.0-SNAPSHOT

* upgrade rpc version to 5.10.0-SNAPSHOT

---------

Co-authored-by: liujianjun.ljj <liujianjun.ljj@antgroup.com>

* Custom serializer register (#1296)

* feat: use extension on serializer register
---------

Co-authored-by: 均源 <zhangminglun.zml@antgroup.com>
Co-authored-by: junyuan <zhangminglun.zml@ant-group.com>

* chore: update version to release (#1328)

Co-authored-by: lo1nt <zhangminglun.zml@ant-group.com>

* upgrade rpc version to 5.10.1-SNAPSHOT (#1334)

Co-authored-by: liujianjun.ljj <liujianjun.ljj@antgroup.com>

* support change grpc maxInboundMessageSize (#1333)

Co-authored-by: liujianjun.ljj <liujianjun.ljj@antgroup.com>

* Fix the unit test message too large problem (#1339)

* support change grpc maxInboundMessageSize

* fix the debug body message too large problem

---------

Co-authored-by: liujianjun.ljj <liujianjun.ljj@antgroup.com>

* feat: bump hessian from 3.13.3 to 3.4.0 (#1338)

Co-authored-by: Lo1nt <zhangminglun.zml@antgroup.com>

* updapte 5.10.1 version to release (#1337)

Co-authored-by: Lo1nt <zhangminglun.zml@antgroup.com>

* update version

* bump hessian

* update version

* add ci

* set verison as 51100

* fix: destory

* fix: unit test

---------

Co-authored-by: evenliu <evenljj@163.com>
Co-authored-by: liujianjun.ljj <liujianjun.ljj@antgroup.com>
Co-authored-by: lo1nt <zhangminglun.zml@ant-group.com>
Co-authored-by: lo1nt <zhangminglun.zml@antgroup.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants