đŸ’Ÿ Archived View for hyperborea.org â€ș howto â€ș groovy-null.gmi captured on 2021-12-03 at 14:04:38. Gemini links have been rewritten to link to archived content

View Raw

More Information

âžĄïž Next capture (2024-06-20)

-=-=-=-=-=-=-

⬜ Groovy, null, and ‘null’

Groovy will let you call toString() on a null object. The result is the word ‘null’, which might be what you’re expecting if you know the object is null, but probably isn’t what you’re expecting if you don’t.

So if you’re, say, binding a SQL parameter and you forget to check for nulls like you would in Java, and you forget to use a null-safe operator like you should in Groovy, and you get a null value, what happens? Does groovy


Throw a NullPointerException like Java?

Set the field to null?

Neither. It sets the field to the string ‘null’.

Make sure to use myVariable?.toString() instead of myVariable.toString() for cases like this!

—Kelson Vibber, 2018-03-28

Originally posted on K-Squared Ramblings

More Tips

Fediverse: KelsonV@Wandering.shop