JDK-8223112 : Clarify operational semantics of java.util.Objects.equals()
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 11,12,13
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2019-04-26
  • Updated: 2022-04-15
  • Resolved: 2019-05-03
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 13
13 b20Fixed
Related Reports
CSR :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
not OS / runtime specific issue.

A DESCRIPTION OF THE PROBLEM :
In Objects.equals(myObject1, myObject2), if myObject2 is null and if myObject1.equals() doesn't handle null check, nullPointerException will be thrown. 

JavaDoc says, false will be returned if either of the parameter is null but it is not handled for second parameter.


FREQUENCY : always



Comments
URL: http://hg.openjdk.java.net/jdk/jdk/rev/90855d9c3c39 User: darcy Date: 2019-05-03 16:26:09 +0000
03-05-2019

Exact implementation used for Objects.equals discussed in review thread: http://mail.openjdk.java.net/pipermail/core-libs-dev/2009-September/002580.html
02-05-2019

Review thread: http://mail.openjdk.java.net/pipermail/core-libs-dev/2019-May/060000.html
02-05-2019

The assumption is that every implementation of equals(null) should be handled by the class itself.
30-04-2019

As per the documentation at https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/util/Objects.html#equals(java.lang.Object,java.lang.Object) : "if exactly one argument is null, false is returned. " As per the implementation, if the first argument is null , it will return false otherwise it is delegated to the equals() method of the first argument .The result is then dependent on whether the equals() method of the first argument follows the contract properly or not. As such the documentation should not guarantee that if any of the arguments is null, false will be returned .
30-04-2019