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

NullPointerException raised by POJOAnnotationFormatter.format(...) #318

Closed
dgrandemange opened this issue May 25, 2017 · 3 comments
Closed
Labels
Milestone

Comments

@dgrandemange
Copy link
Contributor

Hi again,

Lately, i face a situation where
POJOAnnotationFormatter.format(java.lang.Object argumentToFormat, Formatf annotation)
raise a NullPointerException.

This occurs when received parameter argumentToFormat is null.
My POJOAnnotationFormatter implementation clearly misses something here.
This could be fixed by early inserting a check to test if argumentToFormat is null, and if that is the case, immediatly return null which, IMHO, is better than returning an empty string (can't see any indication about this in interface AnnotationArgumentFormatter.format(java.lang.Object argumentToFormat, Formatf annotation) contract though.)
By returning null (rather than an empty string), this make this null POJO object further evictable when part of a @Table formatting where attribute includeNullColumns is set to false.

@janschaefer
Copy link
Contributor

Hi,
this is somehow related to #315. I am not sure about your suggested solution. The format method should return a String and it should never be null actually (documentation is not precise here), because other JGiven code depends on this (see discussion in #315).

dgrandemange pushed a commit to dgrandemange/JGiven that referenced this issue May 27, 2017
fix POJOAnnotationFormatter to return literal string "null" when given
object is null
complete datatable examples to test this behavior
migrate datatable examples model/format/annotation classes to src/main
@dgrandemange
Copy link
Contributor Author

Ok, thank you for the clarification.

Datatable examples have been completed to reproduce the issue.
The fix simply consists in returning a "null" string in case given object is null, and is available in PR #319.

dgrandemange pushed a commit to dgrandemange/JGiven that referenced this issue May 27, 2017
jgiven-examples : add compile dependency to jgiven-core
dgrandemange pushed a commit to dgrandemange/JGiven that referenced this issue Jun 4, 2017
java 1.6 compatibility
janschaefer pushed a commit that referenced this issue Jun 15, 2017
fix POJOAnnotationFormatter to return literal string "null" when given
object is null
complete datatable examples to test this behavior
migrate datatable examples model/format/annotation classes to src/main
janschaefer pushed a commit that referenced this issue Jun 15, 2017
jgiven-examples : add compile dependency to jgiven-core
janschaefer pushed a commit that referenced this issue Jun 15, 2017
java 1.6 compatibility
@janschaefer
Copy link
Contributor

Fixed by #319

@janschaefer janschaefer added this to the v0.15.2 milestone Jun 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants