Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null Pointer Exception while integrating swagger coverage with karate framework #145

Open
1 task done
dtk72 opened this issue Jul 4, 2023 · 13 comments
Open
1 task done

Comments

@dtk72
Copy link

dtk72 commented Jul 4, 2023

I'm submitting a ...

  • 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.
@Fresh-D101
Copy link
Contributor

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

@dtk72
Copy link
Author

dtk72 commented Jul 4, 2023

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]

@Fresh-D101
Copy link
Contributor

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?

@dtk72
Copy link
Author

dtk72 commented Jul 6, 2023

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

@tsbirch
Copy link

tsbirch commented Dec 1, 2023

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!

@Fresh-D101
Copy link
Contributor

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!

@tsbirch
Copy link

tsbirch commented Jan 4, 2024

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

@tdeverdiere
Copy link

tdeverdiere commented Jan 5, 2024

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"

@anneChen8888
Copy link

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
Copy link

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?

@tdeverdiere
Copy link

tdeverdiere commented Mar 15, 2024

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

@kwokfu
Copy link

kwokfu commented Apr 27, 2024

This looks like related to karatelabs/karate#2048

@kondababubalam
Copy link

can you share repo @tdeverdiere

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants