← All tasks
javasofastack/sofa-boot #478Not a task: already works

Error java.lang.LinkageError occurred when use sofa-boot(v3.2.0) and sofa-ark(v1.0.0) together

envgap__sofastack__sofa-boot-478

01 / FAILURE SIGNATURE

As reported upstream

Based on sofa-boot v3.2.0 and sofa-ark 1.0.0, when I started application, I got a error:
Not a benchmark task.
  • The project already builds and runs before the fix, so there is nothing to repair.

02 / ENVIRONMENT RECIPE

Base commit
971496b0424516184b5f0a514da918a6732baf39
Manifest
sofa-boot-project/sofa-boot-plugins/runtime-sofa-boot-plugin/pom.xml
Reproduce
Awaiting issue-specific recipe
Run under trace
Awaiting a meaningful runtime command

03 / ORIGINAL ISSUE TEXT

sofastack/sofa-boot #478 · read the original issue
Based on sofa-boot v3.2.0 and sofa-ark 1.0.0, when I started application, I got a error:



```

Caused by: java.lang.LinkageError: loader constraint violation: when resolving interface method "com.alipay.sofa.runtime.spi.component.SofaRuntimeManager.registerShutdownAware(Lcom/alipay/sofa/runtime/spi/spring/RuntimeShutdownAware;)V" the class loader (instance of com/alipay/sofa/ark/container/service/classloader/BizClassLoader) of the current class, com/alipay/sofa/runtime/spring/RuntimeShutdownAwarePostProcessor, and the class loader (instance of com/alipay/sofa/ark/container/service/classloader/PluginClassLoader) for the method's defining class, com/alipay/sofa/runtime/spi/component/SofaRuntimeManager, have different Class objects for the type com/alipay/sofa/runtime/spi/spring/RuntimeShutdownAware used in the signature

```

After analysis, I found it's caused by that runtime-sofa-boot-plugin did not export `com.alipay.sofa.runtime.spi.spring.RuntimeShutdownAware`. Because `RuntimeShutdownAwarePostProcessor` was loaded by bizClassLoader, `SofaRuntimeManager` was loaded by pluginClassLoader, they both imported `RuntimeShutdownAware`, so two RuntimeShutdownAware classes ware loaded separately by bizClassLoader and pluginClassLoader, when `RuntimeShutdownAwarePostProcessor` tried to call `SofaRuntimeManager`'s register method with a RuntimeShutdownAware instance, this error occurred.



Sofa-boot v3.1.5 did not have such issue, because `RuntimeShutdownAwarePostProcessor` was not added then (replacement of `ApplicationShutdownCallbackPostProcessor`?), and no other classes used `RuntimeShutdownAware`.



By the way, the class comment on `RuntimeShutdownAwarePostProcessor` is `since 2.5.0`, it's a little misleading, should it be `since 3.2.0`?



I think no harm done to export `com.alipay.sofa.runtime.spi.spring.RuntimeShutdownAware` by runtime-sofa-boot-plugin, that prevent bizClassLoader from loading this class. If you agree what I analyzed, I will submit a PR to fix this. 
Continue on GitHub ↗

04 / LABELS

Labels from the report text only; not yet run

No supported category has been assigned.

Label rules and the text that matched
[]