JDK 8 code review request for 8011800: Add java.util.Objects.requireNonNull(T, Supplier<String>)

Joseph Darcy joe.darcy at oracle.com
Thu Apr 11 02:41:53 UTC 2013

On 4/10/2013 5:02 AM, Remi Forax wrote:
> On 04/09/2013 11:12 PM, Joe Darcy wrote:
>> Hello,
>> Please review my changes for
>>     8011800: Add java.util.Objects.requireNonNull(T, Supplier<String>)
>>     http://cr.openjdk.java.net/~darcy/8011800.0/
>> which add a new method to java.util.Objects to take a 
>> Supplier<String> rather than a String.
>> Patch inline below.
>> Thanks,
>> -Joe
> It's premature in my opinion to introduce this kind of method in the API.
> The cost of creating a lambda the first time is actually even worst as 
> the one
> of loading an inner class. Objects.requireNonNull should be a quick 
> check,
> not something that involve to load a new class.
> It's true that the JIT will optimize the lambda creation but there are 
> lot of codes
> that are never JITed, typically less than 20% of the code of a program 
> is JITed.
> Adding this API will slow down the startup time of a program,
> Java is known to be slow at startup, in fact, the VM is not that slow, 
> the JDK and
> the application are slow to startup. It's not a good idea to provide a 
> way
> to make the startup of an application slower that it needs to be.

Acting as legal counsel for Objects.requireNonNull(T, Supplier<String>), 
I submit a plea of "not guilty" to the charge of slowing down Java 
startup. First, the method isn't in the JDK yet. Second, even if it were 
in the JDK, it would first have to be used in a startup-critical way. 
Third, the method contains a disclaimer warning against misuse.


More information about the core-libs-dev mailing list