đŸ Archived View for hyperborea.org âș tech-tips âș groovy-null.gmi captured on 2024-08-31 at 12:27:15. Gemini links have been rewritten to link to archived content
âŹ ïž Previous capture (2022-04-28)
-=-=-=-=-=-=-
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