JDK-4529353 : java.awt.DisplayMode.equals( DisplayMode ) does not check for null
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2001-11-20
  • Updated: 2003-09-11
  • Resolved: 2003-09-11
Related Reports
Duplicate :  
Description

Name: gm110360			Date: 11/19/2001


java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)

As can be seen from DisplayMode source equals( DisplayMode ) doesn't check null.

    public boolean equals(DisplayMode dm) {
        return (getHeight() == dm.getHeight()
            && getWidth() == dm.getWidth()
            && getBitDepth() == dm.getBitDepth()
            && getRefreshRate() == dm.getRefreshRate());
    }

Also, shouldn't DisplayMode override equals( Object ) and call equals( displayMode ) if obj instanceof DisplayMode?
(Review ID: 134949) 
======================================================================

Comments
WORK AROUND Name: gm110360 Date: 11/19/2001 Check for null before calling DisplayMode.equals( DisplayMode ) ======================================================================
11-06-2004

SUGGESTED FIX public boolean equals(Object o) { if (!o instanceof DisplayMode) { return false; } ... } Actually, we cannot take out the equals(DisplayMode) method since it is now part of the public API (and removing it would cause binary incompatibility). However, we can add the above method (equals(Object)). Note that the null check should be done in equals(DisplayMode) because a call to equals(null) will go to the DisplayMode version of the method, not the equals(Object) version. See 4634385 for more details
11-06-2004

EVALUATION This is definitely a problem (see page 35 of Effective Java by Josh Bloch). However, it requires a slight API change (see suggested fix) and should be fixed in tiger. ###@###.### 2001-11-20 Since we are adding the new API suggested (equals(Object)) as a fix for 4634385, we should fix this bug at the same time. Closing this bug as a duplicate of 4634385 just to simplify things... ###@###.### 2003-09-11
11-09-2003