Bug 568197 - Bug: Using .equals to compare two org.eclipse.jdt.core.IJavaElement[]'s in TypeHierarchyViewPart.java
Summary: Bug: Using .equals to compare two org.eclipse.jdt.core.IJavaElement[]'s in Ty...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.18   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.18 M3   Edit
Assignee: Jeff Johnston CLA
QA Contact: Jeff Johnston CLA
URL:
Whiteboard: 4.18M2
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-24 08:45 EDT by Carsten Hammer CLA
Modified: 2020-11-17 14:32 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carsten Hammer CLA 2020-10-24 08:45:13 EDT
Bug: Using .equals to compare two org.eclipse.jdt.core.IJavaElement[]'s, (equivalent to ==) in org.eclipse.jdt.internal.ui.typehierarchy.TypeHierarchyViewPart.updateInput(IJavaElement[])

This method invokes the .equals(Object o) method on an array. Since arrays do not override the equals method of Object, calling equals on an array is the same as comparing their addresses. To compare the contents of the arrays, use java.util.Arrays.equals(Object[], Object[]). To compare the addresses of the arrays, it would be less confusing to explicitly check pointer equality using ==. 

Rank: Scariest (3), confidence: Normal
Pattern: EC_BAD_ARRAY_COMPARE 
Type: EC, Category: CORRECTNESS (Correctness)

This bug has been introduced in Bug 21417

see the following commit

commit 4db882a354cc2434c1f22f9f6d664a1ea86ce1d3
Author: Raksha Vasisht <rvasisht> 2010-09-13 21:41:04
Committer: Raksha Vasisht <rvasisht> 2010-09-13 21:41:04
Parent: 3a22874430e83da885df96967ad295af40285434 (Fixed bug 304217: [type hierarchy] Widget is disposed error on type hierarchy computation)
Child: 6149731d53aecdf58a16b1ff680682bf9d4436d4 (Fixed bug 325250: [type hierarchy] Improve label in history dropdown for Multi-select Java elements and show in Type Hierarchy)
Branches: change/144108/30, change/144108/33, change/144108/36, change/144108/37, change/144108/40, change/144108/46, change/144110/29, change/144110/31, change/144110/33, change/144110/35, change/144113/16, change/144113/18, change/144557/7, change/144558/6, change/144558/7, change/144558/8, change/144558/9, change/144559/9, change/144559/10, change/144559/11, change/144562/14, change/144563/10 and 218 more branches

Fixed bug 21417:  [type hierarchy] Multi-select packages and show in Type Hierarchy

Before this commit the signature of the method

private void updateInput(IJavaElement[] inputElements)

was 

private void updateInput(IJavaElement inputElement)

The corresponding of the new comparison

if (!inputElements.equals(prevInput)) {

was before 

if (!inputElement.equals(prevInput)) {

so it made use of the equals method of the IJavaElement before and now compares by reference. I think it is broken now. How to test?
Comment 2 Jeff Johnston CLA 2020-10-29 15:08:09 EDT
Released for 4.18M3
Comment 3 Jeff Johnston CLA 2020-11-17 14:32:56 EST
Verified for 4.18M3 using I20201117-0600 build