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

NPE with @Table(includeNullColumns=true and fieldsFormatSetAnnotation) #315

Closed
nikowitt opened this issue May 2, 2017 · 10 comments
Closed
Assignees
Milestone

Comments

@nikowitt
Copy link
Contributor

nikowitt commented May 2, 2017

Using @table with includeNullColumns = true and a fieldsFormatSetAnnotation results in a NPE when a column value really has null values:

java.lang.NullPointerException
	at com.tngtech.jgiven.report.text.PlainTextTableWriter.hasNewline(PlainTextTableWriter.java:106)
	at com.tngtech.jgiven.report.text.PlainTextTableWriter.handleNewLines(PlainTextTableWriter.java:63)
	at com.tngtech.jgiven.report.text.PlainTextTableWriter.writeDataTable(PlainTextTableWriter.java:29)
	at com.tngtech.jgiven.report.text.PlainTextScenarioWriter.printDataTable(PlainTextScenarioWriter.java:178)
	at com.tngtech.jgiven.report.text.PlainTextScenarioWriter.printStep(PlainTextScenarioWriter.java:139)
	at com.tngtech.jgiven.report.text.PlainTextScenarioWriter.visit(PlainTextScenarioWriter.java:93)
	at com.tngtech.jgiven.report.model.StepModel.accept(StepModel.java:77)
	at com.tngtech.jgiven.report.model.ScenarioCaseModel.accept(ScenarioCaseModel.java:73)
	at com.tngtech.jgiven.report.model.ScenarioModel.accept(ScenarioModel.java:28)
	at com.tngtech.jgiven.report.text.PlainTextReporter.visit(PlainTextReporter.java:68)
	at com.tngtech.jgiven.report.model.ScenarioModel.accept(ScenarioModel.java:26)
	at com.tngtech.jgiven.report.model.ReportModel.accept(ReportModel.java:45)
	at com.tngtech.jgiven.report.text.PlainTextReporter.write(PlainTextReporter.java:51)
	at com.tngtech.jgiven.report.impl.CommonReportHelper.finishReport(CommonReportHelper.java:30)
	at com.tngtech.jgiven.junit.JGivenClassRule.finished(JGivenClassRule.java:22)
	at org.junit.rules.TestWatcher.finishedQuietly(TestWatcher.java:117)
	at org.junit.rules.TestWatcher.access$400(TestWatcher.java:46)
	at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:64)
	at org.junit.rules.RunRules.evaluate(RunRules.java:20)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

using includeNullColumns=false not using fieldsFormatSetAnnotation solves this issue.

Best regards,
Niko

UPDATE: it seems that includeNullColumns not always solved the issue. Using a @NamedFormat on a
update: it seems that includeNullColumns not always solved the issue. Using a @NamedFormat on anull value (even when null is covered in the formatter implementation) still triggers the NPE.

@janschaefer janschaefer added this to the v0.15.1 milestone May 2, 2017
@janschaefer
Copy link
Contributor

thanks for reporting!

@janschaefer
Copy link
Contributor

Issue is fixed by d2fe787

@nikowitt
Copy link
Contributor Author

nikowitt commented May 8, 2017

Thanks very much! I've tried my test once more. The test itself seems to run smoothly now, but it seems that there is still a similar issue during the report creation:

java.lang.NullPointerException
	at com.tngtech.jgiven.report.text.PlainTextTableWriter.getColumnSpecs(PlainTextTableWriter.java:119)
	at com.tngtech.jgiven.report.text.PlainTextTableWriter.writeDataTable(PlainTextTableWriter.java:31)
	at com.tngtech.jgiven.report.text.PlainTextScenarioWriter.printDataTable(PlainTextScenarioWriter.java:178)
	at com.tngtech.jgiven.report.text.PlainTextScenarioWriter.printStep(PlainTextScenarioWriter.java:139)
	at com.tngtech.jgiven.report.text.PlainTextScenarioWriter.visit(PlainTextScenarioWriter.java:93)
	at com.tngtech.jgiven.report.model.StepModel.accept(StepModel.java:77)
	at com.tngtech.jgiven.report.model.ScenarioCaseModel.accept(ScenarioCaseModel.java:73)
	at com.tngtech.jgiven.report.model.ScenarioModel.accept(ScenarioModel.java:28)
	at com.tngtech.jgiven.report.text.PlainTextReporter.visit(PlainTextReporter.java:68)
	at com.tngtech.jgiven.report.model.ScenarioModel.accept(ScenarioModel.java:26)
	at com.tngtech.jgiven.report.model.ReportModel.accept(ReportModel.java:45)
	at com.tngtech.jgiven.report.text.PlainTextReporter.write(PlainTextReporter.java:51)
	at com.tngtech.jgiven.report.impl.CommonReportHelper.finishReport(CommonReportHelper.java:30)
	at com.tngtech.jgiven.junit.JGivenClassRule.finished(JGivenClassRule.java:22)
	at org.junit.rules.TestWatcher.finishedQuietly(TestWatcher.java:117)
	at org.junit.rules.TestWatcher.access$400(TestWatcher.java:46)
	at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:64)
	at org.junit.rules.RunRules.evaluate(RunRules.java:20)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Best regards,
Niko

@janschaefer janschaefer reopened this May 8, 2017
@janschaefer janschaefer modified the milestones: v0.15.2, v0.15.1 May 8, 2017
@janschaefer janschaefer self-assigned this May 8, 2017
@janschaefer
Copy link
Contributor

Ok, I will create a more complete test case.

@janschaefer
Copy link
Contributor

I could not reproduce the issue. Could you provide a minimal example that causes the problem?

@nikowitt
Copy link
Contributor Author

nikowitt commented May 8, 2017

Sure, I hope I can do this tomorrow morning.

@janschaefer
Copy link
Contributor

I think it might depend on your formatter implementation. The problem might be that your formatter implementation returns null where it should not. This, however, is also not documented in the API.

@nikowitt
Copy link
Contributor Author

nikowitt commented May 8, 2017

Oh, this indeed could be the case - let me should doublecheck this.

@nikowitt
Copy link
Contributor Author

nikowitt commented May 8, 2017

Very good catch, this indeed is the case, I'm returning null instead of blank in one used formatter. Changing this solves the issue. Maybe the exception thrown there could be improved to give a hint in the right direction?

@janschaefer
Copy link
Contributor

Yes, definitely. And the documentation should be more clear about this.

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

No branches or pull requests

2 participants