My project has the following code:
params.stringValue?.trim().replaceAll('aa', 'a')
We expected that if params.stringValue was null, then both trim() and replaceAll() would not be called.
However, we got a NullPointerException on this line, saying that replaceAll() could not be called on a null object.
We had to change the code like this:
params.stringValue?.trim()?.replaceAll('aa', 'a')
Why doesn't the first code snippet above work? Is it a mistake in Groovy that he continues to evaluate an expression after one zero has been encountered?
source share