swagger-coverage icon indicating copy to clipboard operation
swagger-coverage copied to clipboard

Null Pointer Exception while integrating swagger coverage with karate framework

Open dtk72 opened this issue 2 years ago • 14 comments

I'm submitting a ...

  • [x] bug report

Error when running mvn clean test

java.lang.NullPointerException: Cannot invoke "java.nio.file.attribute.FileTime.toInstant()" because "this.minResultTime" is null

If the current behavior is a bug, please provide steps to reproduce, broken swagger specification and swagger-coverage-output:

Followed this code example provided in the README to generate a swagger coverage report after running karate tests for my own API:

import java.net.URI;
import com.github.viclovsky.swagger.coverage.karate.SwaggerCoverageRunner;
import com.intuit.karate.Results;
import org.junit.jupiter.api.Test;

public class CoverageReportRunner {

    @Test
    void testAll(){
        Results results = SwaggerCoverageRunner.path("classpath:some/path")
                .coverageDir("api-test-coverage")
                .swaggerSpec(URI.create("https://petstore3.swagger.io/api/v3/openapi.json"))
                .oas3()
                .outputJunitXml(true)
                .karateEnv("dev")
                .parallel(1);
    }
}

The error seems to arise when the code reaches .parallel(1)

Other information

  • The swaggerSpec() is passed a path to the .yaml file instead of a URL
  • The Coverage directory and naming conventions are followed appropriately, dependencies are added (Maven), and Java 16 and Junit5 are being used.

dtk72 avatar Jul 04 '23 11:07 dtk72

Hey! Could you please provide the full call stack for the error?

Fresh-D101 avatar Jul 04 '23 14:07 Fresh-D101

Hi! For sure,

java.lang.NullPointerException: Cannot invoke "java.nio.file.attribute.FileTime.toInstant()" because "this.minResultTime" is null
 at com.github.viclovsky.swagger.coverage.core.results.builder.prebuilder.GenerationStatisticsBuilder.build([GenerationStatisticsBuilder.java:60]
 at com.github.viclovsky.swagger.coverage.core.generator.Generator.lambda$run$1([Generator.java:49]
 at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept([ForEachOps.java:183]
 at java.base/java.util.stream.ReferencePipeline$2$1.accept([ReferencePipeline.java:179]
 at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining([ArrayList.java:1625]
 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.ForEachOps$ForEachOp.evaluateSequential([ForEachOps.java:150]
 at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential([ForEachOps.java:173]
 at java.base/java.util.stream.AbstractPipeline.evaluate([AbstractPipeline.java:234]
 at java.base/java.util.stream.ReferencePipeline.forEach([ReferencePipeline.java:596]
 at com.github.viclovsky.swagger.coverage.core.generator.Generator.run([Generator.java:48]
 at com.github.viclovsky.swagger.coverage.karate.SwaggerCoverageRunner$SwaggerCoverageBuilder.generateReport([SwaggerCoverageRunner.java:126]
 at com.github.viclovsky.swagger.coverage.karate.SwaggerCoverageRunner$SwaggerCoverageBuilder.parallel([SwaggerCoverageRunner.java:163]
 at TestRunner.testAll([TestRunner.java:16]
 at java.base/java.util.ArrayList.forEach([ArrayList.java:1511]
 at java.base/java.util.ArrayList.forEach([ArrayList.java:1511]

dtk72 avatar Jul 04 '23 14:07 dtk72

Hey, sorry for the late response, I'm super busy atm. I had a quick look at it, and I think I know what could be going on. Can you maybe share the log file?

Fresh-D101 avatar Jul 05 '23 21:07 Fresh-D101

No worries, I've attached the file: log4j.log

dtk72 avatar Jul 06 '23 19:07 dtk72

Hi, I've recently bumped into this same issue and would really like to try this module to check swagger coverage with Karate. Do you have any updates on this? Thank you!

tsbirch avatar Dec 01 '23 09:12 tsbirch

Hey guys, sorry I haven't gotten back to you on this issue. Can you also provide me with your log4j.log file and ideally a small reproduction project? I will try to take a look at this asap!

Fresh-D101 avatar Dec 04 '23 13:12 Fresh-D101

Hi, sorry I hadn't come back to this issue. I managed to prepare a small reproduction project (which I've attached), but wasn't able at first to get the error above.

I was finally able to reproduce the null pointer exception, but only if I change protocol to https in karate-config.js when the proxy is used (which is wrong):

if (karate.properties['proxy.port']){ console.log("Proxy server is used"); protocol = "https"; }

My main problem, though, is I'm not able to run tests using the proxy with https endpoints. I tried the workaround described here:

https://github.com/viclovsky/swagger-coverage/blob/master/swagger-coverage-karate/README.md#-the-problem-with-https-and-the-workaround

but with no success. Is it possible to work with https while using the proxy to measure swagger coverage?

Thanks again! myproject.zip

tsbirch avatar Jan 04 '24 12:01 tsbirch

I 've got the same error and same stack than the one from @dtk72 when i upgrade version of karate 1.4.1 and other libraries:

Update karate version to 1.4.1

Update jackson to 2.5.13 to be compatible

Update other libraries:
- armeria 1.26.4
- classgraph 4.8.165
- netty 4.1.104
- thymeleaf 3.1.2.RELEASE
- wiremock 2.27.2

https://github.com/tdeverdiere/swagger-coverage/tree/update-karate

Error : "java.lang.NullPointerException: Cannot invoke "java.nio.file.attribute.FileTime.toInstant()" because "this.minResultTime" is null"

tdeverdiere avatar Jan 05 '24 06:01 tdeverdiere

I got same issue, karate version is 1.4.0, swagger-coverage version is 1.5.0

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.nio.file.attribute.FileTime.toInstant()" because "this.minResultTime" is null
        at com.github.viclovsky.swagger.coverage.core.results.builder.prebuilder.GenerationStatisticsBuilder.build(GenerationStatisticsBuilder.java:60)
        at com.github.viclovsky.swagger.coverage.core.generator.Generator.lambda$run$1(Generator.java:49)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
        at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
        at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
        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.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
        at com.github.viclovsky.swagger.coverage.core.generator.Generator.run(Generator.java:48)
        at com.github.viclovsky.swagger.coverage.CommandLine.run(CommandLine.java:77)
        at java.base/java.util.Optional.orElseGet(Optional.java:362)
        at com.github.viclovsky.swagger.coverage.CommandLine.main(CommandLine.java:34)

anneChen8888 avatar Mar 15 '24 02:03 anneChen8888

I 've got the same error and same stack than the one from @dtk72 when i upgrade version of karate 1.4.1 and other libraries:

Update karate version to 1.4.1

Update jackson to 2.5.13 to be compatible

Update other libraries:
- armeria 1.26.4
- classgraph 4.8.165
- netty 4.1.104
- thymeleaf 3.1.2.RELEASE
- wiremock 2.27.2

https://github.com/tdeverdiere/swagger-coverage/tree/update-karate

Error : "java.lang.NullPointerException: Cannot invoke "java.nio.file.attribute.FileTime.toInstant()" because "this.minResultTime" is null"

Is the issue fixed on your side?

anneChen8888 avatar Mar 15 '24 02:03 anneChen8888

Hello No so i created an implementation of a Karate RuntimeHook: SwaggerCoverageRuntimeHook And use it in the Runner configuration:

        Results results = Runner.path("classpath:...")
                .outputCucumberJson(true)
                .outputJunitXml(true)
                .hook(new SwaggerCoverageRuntimeHook("target", "target/test-classes/swagger-coverage-config.json"))
                .reportDir(karateOutputPath)
                .parallel(1);

To write SwaggerCoverageRuntimeHook i mostly use the code from swagger-coverage-karate: SwaggerCoverageRunner#generateReport And i copy also the all class Generator from swagger-coverage-commandline/src/main/java/com/github/viclovsky/swagger/coverage/core/generator/Generator.java

I could give you the all code in my repo if you want

tdeverdiere avatar Mar 15 '24 08:03 tdeverdiere

This looks like related to https://github.com/karatelabs/karate/issues/2048

kwokfu avatar Apr 27 '24 16:04 kwokfu

can you share repo @tdeverdiere

kondababubalam avatar May 23 '24 08:05 kondababubalam

@tdeverdiere can you share the repo or provide any pointers on how to integrate this tool into Karate Runner? Thanks

rc2201 avatar Aug 21 '24 04:08 rc2201