Skip to content

ExtentSparkReporter constructor throws NullPointerException if path argument don`t contains parrent fodler #259

@mishust1n

Description

@mishust1n

Steps to reproduce:

  DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss");
        String fileName = "raport-" + LocalDateTime.now().format(formatter) + ".html";

        ExtentSparkReporter spark = new ExtentSparkReporter(Paths.get( fileName).toFile())

                .viewConfigurer()
                .viewOrder()
                .as(new ViewName[]{ViewName.TEST, ViewName.DASHBOARD, ViewName.EXCEPTION}).apply();

Observed behavior:


Exception in thread "main" java.lang.NullPointerException
	at com.aventstack.extentreports.reporter.AbstractFileReporter.<init>(AbstractFileReporter.java:45)
	at com.aventstack.extentreports.reporter.ExtentSparkReporter.<init>(ExtentSparkReporter.java:55)
	at utils.TestReport.init(TestReport.java:32)
	at utils.TestInitialization.init(TestInitialization.java:37)
	at listener.ListenerPlugin.onTestRunStarted(ListenerPlugin.java:25)
	at io.cucumber.core.eventbus.AbstractEventPublisher.send(AbstractEventPublisher.java:51)
	at io.cucumber.core.eventbus.AbstractEventBus.send(AbstractEventBus.java:12)
	at io.cucumber.core.runtime.CucumberExecutionContext.emitTestRunStarted(CucumberExecutionContext.java:64)
	at io.cucumber.core.runtime.CucumberExecutionContext.startTestRun(CucumberExecutionContext.java:52)
	at io.cucumber.core.runtime.Runtime.run(Runtime.java:77)
	at io.cucumber.core.cli.Main.run(Main.java:78)
	at io.cucumber.core.cli.Main.main(Main.java:33)

Exception throws bolded line if (!parentFile.exists()) {

    protected AbstractFileReporter(File f) {
        this.file = f;
        File parentFile;
        if (Files.isDirectory(f.toPath(), new LinkOption[0])) {
            parentFile = f;
        } else {
            parentFile = f.getParentFile();
        }

        if (!parentFile.exists()) {
            parentFile.mkdirs();
        }

    }

If f argument created without parent folder (new File(fileName.html)), parent file will be always null,
But if argument will be new File (folderName\fileName.html) folder name and parent folder will be successfully created.

Expected behavior:

Argument f cab be just file name without parent folder.

Version: 5.0.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions