đŸ 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
âĄïž Next capture (2024-06-20)
-=-=-=-=-=-=-
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