commons-lang icon indicating copy to clipboard operation
commons-lang copied to clipboard

Let mid(null), left(null) and right(null) return empty

Open senderic opened this issue 4 years ago • 3 comments

I'm not sure if there is reasoning behind left(null, n) returning null, but other StringUtils functions tends to return empty strings if their inputs are null. Likewise, I think it makes sense that mid(null, n), left(null, n) or right(null, n) returns an empty string instead of returning null. My use case is lambda logging. I have code like this:

log.debug("My output (first 256 chars): {}", StringUtils.left(output, 256)::toString);

I get an NullPointerExceptions when I do and not properly wrap the call, etc. So I can't take advantage of both the left function as well as lambda based logging.

senderic avatar Feb 19 '21 20:02 senderic

Coverage Status

Coverage decreased (-0.002%) to 94.955% when pulling 821a4a5b04f6fb4bbdcec014be48bf42df5f48ca on esend7881:patch-1 into 5689c91cf2a3a27f0a3a8a362857f2cf0919d4f6 on apache:master.

coveralls avatar Feb 19 '21 20:02 coveralls

Coverage Status

Coverage decreased (-0.002%) to 94.955% when pulling 821a4a5b04f6fb4bbdcec014be48bf42df5f48ca on esend7881:patch-1 into 5689c91cf2a3a27f0a3a8a362857f2cf0919d4f6 on apache:master.

I think that is because the total number of lines have been reduced (smaller denominator) which makes it seem like there is less coverage.

senderic avatar Feb 19 '21 22:02 senderic

Not sure about the impact here of changing the behavior... needs a bit more study...

garydgregory avatar Feb 23 '21 14:02 garydgregory