question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StringToIntegerConverter makes TextField throw NullPointerException on null Integer value

See original GitHub issue

Vaadin 14.0.9. Binding a null Integer field to a TextField via StringToIntegerConverter fails with NPE. This is the most basic use-case which simply must work out of the box.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
Legiothcommented, Oct 23, 2019

https://github.com/vaadin/flow/pull/6757 adds a mention of null representations to the exception message.

0reactions
mvysnycommented, Oct 22, 2019

@Legioth very good point with magic+DI, I avoid DI like a plague.

Maybe we should make Binder catch any exception from setValue and rethrow with a more specific message in the case of passing null to a field with a non-null getEmptyValue()?

That sounds really good. Rethrowing as RuntimeException changes exception type which should be avoided. Rethrowing only in special case as described above sounds good to me, and navigates the dev to the correct solution.

We could also consider whether there would be some alternative way of defining explicit null conversion with less boilerplate, e.g. as an optional parameter to the converter constructor. This would on the other hand have a negative impact on code readability.

Yeah, StringToIntegerConverter already has 4 constructors and with optional boolean param there would be too many. We could add converter.withNullValue("") but there’s no point since we can already call binding.withNullRepresentation(""). I think rethrow is the best solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Why do I get NullPointerException when my Integer ...
Integer [] numbers = new Integer[input.toString().length()];. Integer is an object type, so all the values in the array start off as null. If...
Read more >
CRUD component issue - Vaadin
private static BinderCrudEditor<Product> createForm() { TextField name = new ... NullPointerException: Null value is not supported.
Read more >
How to Fix and Avoid NullPointerException in Java - Rollbar
NullPointerException in Java occurs when a variable is accessed which is not pointing to any object and refers to nothing or null.
Read more >
9 Things about null keyword and reference in Java
Any wrapper class with value null will throw java.lang.NullPointerException when Java unbox them into primitive values.
Read more >
How to Handle NullPointerException in Java - freeCodeCamp
The idea is that, when you expect a value to be null , its better to put a null check on that variable....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found