[NEW BUG]: Avoid allocations in String.replace(CharSequence, CharSequence) in case no replacement happened

Christoph Dreis christoph.dreis at freenet.de
Thu Mar 2 11:45:09 UTC 2017

Hey Ulf,

> Hi Vitaly,
> I don't see any contract to throw an NPE:
> https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#replace-
> java.lang.CharSequence-java.lang.CharSequence-
> In any case, what's the reasonable of checking an argument, which is not
> used in that case?
> Am 02.03.2017 um 00:18 schrieb Vitaly Davidovich:
> > Seems like a good idea.  You probably want to null check 'replacement'
> > before the bail out as the method is specified as throwing NPE in that case.

It is stated in the class comment.

"Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown."


More information about the core-libs-dev mailing list