JDK-8073479 : Replace obj.getClass hacks with Objects.requireNonNull
  • Type: Enhancement
  • Component: core-libs
  • Affected Version: 9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2015-02-19
  • Updated: 2015-07-08
  • Resolved: 2015-02-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b53Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
A few places in our class library use the weird trick of using object.getClass() to check for nullity.
While this make seem a smart move, it actually confuses people into believing this is an approved
practice of null checking.

With JDK 7, we have Objects.requireNonNull that provide the proper null checking, and declare the
intent properly. There is no performance implications of using it instead of getClass():
  http://cr.openjdk.java.net/~shade/scratch/NullChecks.java

(Actually, there *are* a few stubborn corner cases with performance implications; see JDK-8042127.)
Comments
Discussion: http://mail.openjdk.java.net/pipermail/core-libs-dev/2015-February/031631.html
20-02-2015

Webrev: http://cr.openjdk.java.net/~shade/8073479/webrev.00/
19-02-2015