sermant-io / Sermant

A Cloud-Native Proxyless Service Mesh based on Java Bytecode Enhancement Technology
https://sermant.io/
Apache License 2.0
1.26k stars 170 forks source link

Launch demo reported "java.lang.ClassFormatError:Truncated class file" #1309

Closed godtroop-github closed 1 year ago

godtroop-github commented 1 year ago

What happened?

when just clone the repo(develp branch), packaged and deployed the agent plugins, using the router-demo from Sermant-Examples, the program reported a exception after the plugin inited : "java.lang.ClassFormatError:Truncated class file". image

but, when I switch to 1.1.x branch, this can get work.

How can we reproduce it (as minimally and precisely as possible)?

1 clone https://github.com/huaweicloud/Sermant.git 2 run mvn clean package, and deployed all the plugin jars to ${dir}/sermant-agent-1.0.0/agent automatically by maven. 3 clone https://github.com/huaweicloud/Sermant-examples.git 4 launch the router-demo(ZuulApplication), using the VM parameter "-javaagent:/Users/Mac/Documents/GitHub/Sermant/sermant-agent-1.0.0/agent/sermant-agent.jar=appName=zuul" 5 when the program start running , this exception will be found

Anything else we need to know?

Something I just found from the source code, is that I am using the "develop" git branch, and there may be a class isolation is being developing. And the PluginManager#loadPlugins class method has some change: after: image before: image

this may cause define progress can't load the correct class bytes, because the ClassUtils#defineClass only search SystemClassLoader and ContextClassLoader.

I guess may be that's reason for this issue.

Sermant version

develop & 1.1.x branch

OS version

```console # On Linux: $ cat /etc/os-release # paste output here $ uname -a # paste output here # On Windows: C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture # paste output here ```

mac os / Apple M2 Max

luanwenfei-venus commented 1 year ago

This is caused by the fact that spring service runs in IDEA. When spring service runs in IDEA, the class loader changes from LaunchedClassLoader to AppClassLoader and cannot get sermant classes which injected through Inject service. Running through jars should avoid this problem.

github-actions[bot] commented 1 year ago

This issue seems to be Stale. We will close it in a few days.

hanbingleixue commented 6 months ago

A solution has been provided. No other problems will occur in the future. Therefore, this issue is closed.