wcm-io / io.wcm.maven.aem-cloud-dependencies

Maven dependencies for the AEM Cloud Service SDK
https://wcm.io/tooling/maven/aem-dependencies.html
Apache License 2.0
2 stars 3 forks source link

Unable to invoke method 'activate' for class org.apache.sling.xss.impl.XSSAPIImpl #60

Closed royteeuwen closed 3 weeks ago

royteeuwen commented 1 month ago

When upgrading to the latest dependencies, I get following exception. Did this occur for you and did you do anything to fix it? I upgraded all other maven dependencies to the latest versions, but it doesn't seem to fix the problem:

java.lang.RuntimeException: Unable to invoke method 'activate' for class org.apache.sling.xss.impl.XSSAPIImpl

    at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.invokeMethod(OsgiServiceUtil.java:366)
    at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.lambda$invokeLifecycleMethod$0(OsgiServiceUtil.java:264)
    at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.findAndInvokeNearestMethod(OsgiServiceUtil.java:150)
    at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.invokeLifecycleMethod(OsgiServiceUtil.java:182)
    at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.activateDeactivate(OsgiServiceUtil.java:98)
    at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.activateInjectServices(OsgiServiceUtil.java:489)
    at org.apache.sling.testing.mock.osgi.MockOsgi.registerInjectActivateService(MockOsgi.java:268)
    at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectActivateService(OsgiContextImpl.java:191)
    at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectActivateService(OsgiContextImpl.java:179)
    at org.apache.sling.testing.mock.sling.context.SlingContextImpl.registerDefaultServices(SlingContextImpl.java:250)
    at io.wcm.testing.mock.aem.context.AemContextImpl.registerDefaultServices(AemContextImpl.java:74)
    at org.apache.sling.testing.mock.sling.context.SlingContextImpl.setUp(SlingContextImpl.java:195)
    at io.wcm.testing.mock.aem.context.AemContextImpl.setUp(AemContextImpl.java:108)
    at io.wcm.testing.mock.aem.junit5.AemContext.setUpContext(AemContext.java:100)
    at io.wcm.testing.mock.aem.junit5.AemContextExtension.setAemContextInStore(AemContextExtension.java:73)
    at io.wcm.testing.mock.aem.junit5.AemContextExtension.postProcessTestInstance(AemContextExtension.java:63)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
    at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
    at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:312)
    at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:735)
    at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:734)
    at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
    at java.base/java.util.Optional.orElseGet(Optional.java:369)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
Caused by: java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    jakarta/json/spi/JsonProvider$Holder.<clinit>()V @7: putstatic
  Reason:
    Type 'org/apache/johnzon/core/JsonProviderImpl' (current frame, stack[0]) is not assignable to 'jakarta/json/spi/JsonProvider'
  Current Frame:
    bci: @7
    flags: { }
    locals: { }
    stack: { 'org/apache/johnzon/core/JsonProviderImpl' }
  Bytecode:
    0000000: bb00 0359 b700 04b3 0001 b1            

    at jakarta.json.spi.JsonProvider.provider(JsonProvider.java:64)
    at jakarta.json.Json.createReaderFactory(Json.java:218)
    at org.apache.sling.xss.impl.XSSAPIImpl.activate(XSSAPIImpl.java:82)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.invokeMethod(OsgiServiceUtil.java:357)
    ... 27 more
stefanseifert commented 1 month ago

this looks like a mismatch of johnzon version and the ongoing switch from javax.json to jakarta.json. also this switch is done for most/lot of sling modules, that's not the case for some of the adobe modules, esp. the adobe core components. within OSGi this is not a problem as each bundle consumes the correct version, but inside the testing classpath this can get to a conflict.

in https://github.com/wcm-io/io.wcm.maven.aem-cloud-dependencies/pull/52 i tried to switch everything to jakarta.json for the testing classpath, but it did not work with adobe core components, so i reverted that in https://github.com/wcm-io/io.wcm.maven.aem-cloud-dependencies/pull/53.

please make sure that all versions of these dependencies in your test classpath use the versions as defined in the aem-cloud-dependencies POM you are using, and not overwritten with a different version:

it does work when code relies on jakarta.json because since some releases sling-mock comes with dependencies akarta.json:jakarta.json-api and org.glassfish:jakarta.json to support those modules that rely on jakarta.json. but it does not work for modules actually relying on the johnzon API, because the johnzon API stays the same between 1.x and 2.x version, but switches the json implementation internally.`