Bug 567225 - Bad array comparison in one of the three HistoryDropDownAction classes
Summary: Bad array comparison in one of the three HistoryDropDownAction classes
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.18   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2020-09-21 16:29 EDT by Carsten Hammer CLA
Modified: 2022-11-27 01:21 EST (History)
0 users

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-09-21 16:29:28 EDT
While in the class org.eclipse.jdt.internal.ui.callhierarchy.HistoryDropDownAction the problem was solved in this commit:

commit b1330e4ae73031eada7bdd49b60f37fd082f370e
Author: Markus Keller <mkeller> 2007-11-06 10:43:59
Committer: Markus Keller <mkeller> 2007-11-06 10:43:59
Parent: 4cdc064a7567f3e815c6ee04dd94e07e631a43a5 (75800: [call hierarchy] should allow searches for fields)
Child: 5695bb15c07bb17312b16e6392d553af7d1f32fc (Removed trailing whitespace and organized the imports)
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 180 more branches

- 207946: [call hierarchy] Call Hierarchy: constructors do not call a type
- 207945: [call hierarchy] Call Hierarchy on initializer should at least have one caller
- 96945: [call hierarchy] Open Call Hierarchy Action does not issue info message if not invoked method call or declaration
- allowing to open the call hierarchy on multiple elements

it is still unsolved in org.eclipse.jdt.internal.ui.typehierarchy.HistoryDropDownAction

see this code:

	private boolean addEntries(Menu menu, List<IJavaElement[]> elements) {
		boolean checked= false;
		int count= 0;
		int min= Math.min(elements.size(), RESULTS_IN_DROP_DOWN);
		for (Iterator<IJavaElement[]> iterator= elements.iterator(); count < min; count++) {
			IJavaElement[] entries= iterator.next();
			if (entries == null || entries.length == 0)
				continue;
			HistoryAction action= new HistoryAction(fHierarchyView, entries);
			action.setChecked(entries.equals(fHierarchyView.getInputElements()));
			checked= checked || action.isChecked();
			addActionToMenu(menu, action);
		}
		return checked;
	}

Here the spotbugs error description:

Bug: Using .equals to compare two org.eclipse.jdt.core.IJavaElement[]'s, (equivalent to ==) in org.eclipse.jdt.internal.ui.typehierarchy.HistoryDropDownAction.addEntries(Menu, List)

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)
Comment 1 Carsten Hammer CLA 2020-09-21 16:34:36 EDT
There are two additional issues of the same kind here:

org.eclipse.jdt.internal.ui.typehierarchy.TypeHierarchyViewPart.setInputElements(IJavaElement[])
org.eclipse.jdt.internal.ui.typehierarchy.TypeHierarchyViewPart.updateInput(IJavaElement[])
Comment 2 Eclipse Genie CLA 2022-11-27 01:21:18 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.