8141652 : Rename methods Objects.nonNullElse* to requireNonNullElse*
Roger.Riggs at Oracle.com
Tue Nov 10 18:55:39 UTC 2015
A few of the proposed replacements of ?: with requireNonNullElse were
because in the particular context, null is an allowed replacement value.
The webrev has been updated to revert changes:
- two uses in
(Line 145 and 160)
- reverted all changes
p.s. the previous webrev is renamed:
On 11/9/2015 2:35 PM, Roger Riggs wrote:
> Hi Stephen,
> On 11/6/2015 10:42 PM, Stephen Colebourne wrote:
>> Seems fine to me.
>> I would have inlined the ZoneId change to one line:
>> String id = Objects.requireNonNullElse(aliasMap.get(zoneId), zoneId);
>> to avoid the local variable change, but no big deal.
> Thanks, I'll fix that.
>> On 6 November 2015 at 20:24, Roger Riggs <Roger.Riggs at oracle.com> wrote:
>>> Please review the renaming of java.util.Object methods, the new
>>> method names
>>> public static <T> T requireNonNullElse(T obj, T defaultObj);
>>> public static <T> T requireNonNullElseGet(T obj, Supplier<?
>>> extends T>
>>> The only remaining possible gotcha for developers is the
>>> method that might be confused with requireNonNullElse(T, T). The longer
>>> name is probably the one you want.
>>> If you see a value that looks like an exception string, you've got
>>> the wrong
>>> To validate some of the uses, I visually scanned src/java.base looking
>>> expressions of the pattern (e1 != null) ? e1 : e2
>>> Most uses of the ternary operator involve either primitive types or
>>> conditions other than != null;
>>> quite a few involved returning null and so were not appropriate to be
>>> 10 files contained relevant expressions:
>>> - 2 should be using Objects.toString() to provide a default value
>>> for a
>>> - 2 can use the requireNonNullElseGet form to delay evaluating the
>>> alternative value.
>>> (2 others were too early in the boot cycle to use lambda).
>>> - The rest followed the expected pattern; though checking if
>>> throwing an
>>> exception was extra work.
>>> Please review and comment.
>>> Thanks for the detailed evaluation and discussion.
More information about the core-libs-dev