renatoathaydes / spock-reports

This project creates a global extension to Spock to create test reports.
Apache License 2.0
273 stars 68 forks source link

Could not initialize class com.athaydes.spockframework.report.internal.ReportDataAggregator #227

Closed sinwe closed 1 year ago

sinwe commented 2 years ago

The test run without issue, IntelliJ and Maven doesn't report it as failure, but I report html file is generated, but it keeps throwing stacktrace as below

Versions: JDK: 11 spock-core: 2.0-groovy-3.0 spock-junit4: 2.0-groovy-3.0 spock-reports: 2.1.1-groovy-3.0 groovy: 3.0.8

Exception in thread "org.spockframework.runtime.RunContext.stop()" java.lang.NoClassDefFoundError: Could not initialize class com.athaydes.spockframework.report.internal.ReportDataAggregator
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:398)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.lambda$createCallStaticSite$2(CallSiteArray.java:65)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallStaticSite(CallSiteArray.java:63)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:55)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:217)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:240)
    at com.athaydes.spockframework.report.internal.HtmlReportAggregator.writeOut(HtmlReportAggregator.groovy:52)
    at com.athaydes.spockframework.report.internal.HtmlReportAggregator$writeOut$0.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callSafe(AbstractCallSite.java:88)
    at com.athaydes.spockframework.report.internal.HtmlReportCreator.done(HtmlReportCreator.groovy:111)
    at com.athaydes.spockframework.report.IReportCreator$done.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callSafe(AbstractCallSite.java:88)
    at com.athaydes.spockframework.report.SpockReportExtension.stop(SpockReportExtension.groovy:72)
    at org.spockframework.runtime.GlobalExtensionRegistry.stopGlobalExtensions(GlobalExtensionRegistry.java:144)
    at org.spockframework.runtime.RunContext.stop(RunContext.java:66)
    at java.base/java.lang.Thread.run(Thread.java:829)
renatoathaydes commented 2 years ago

java.lang.NoClassDefFoundError: Could not initialize class com.athaydes.spockframework.report.internal.ReportDataAggregator

Interesting given that this class has been in spock-reports forever.

Do you have custom class loaders, custom Spock config or anything else that could be causing the classpath to be broken?

renatoathaydes commented 2 years ago

The only static initializers I see in this class that could be throwing an error are these:

    static final charset = Charset.forName( 'utf-8' )
    static final jsonParser = new JsonSlurper()

All JVMs are required to provide the utf-8 charset, so that shouldn't be an issue... JsonSlurper is a Groovy JSON parser that as far as I know is present in every Groovy version and instantiating it should never throw. So there's not much to look at until you can give some more information, perhaps by attaching a debugger at this class and trying to capture the cause of the initialization problem.

renatoathaydes commented 2 years ago

Just crossed my mind you may be missing the groovy-json module in the classpath.

As explained in the README:

The only dependencies this project has are Groovy (only the groovy, groovy-templates, groovy-xml and groovy-json modules are required) and Spock, of course.