Bug 83473 - [Viewers] Open Call Hierarchy fails to find callers sometimes [call hierarchy]
Summary: [Viewers] Open Call Hierarchy fails to find callers sometimes [call hierarchy]
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: PC Linux
: P3 major with 2 votes (vote)
Target Milestone: 3.2 M6   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-21 18:43 EST by Brian Stiles CLA
Modified: 2006-03-30 04:07 EST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Stiles CLA 2005-01-21 18:43:57 EST
1.  Place the cursor on a method or constructor name that is called from one or
more places in the code.

2.  Select Open Call Hierarchy from the context menu.

At this point the Call Hierarchy view should show all the callers of the
selected method.  Since I installed 3.1M4 (upgraded from 3.1M3) I have noticed
that sometimes only the selected method is shown in the Call Hierarchy view.  If
I run the operation a second time, all the expected callers show up in the Call
Hierarchy view.  The same is sometimes true when expanding a caller node.    The
expanded node may appear empty, but after rerunning the operation, that node
will exand to show its callers.

As of yet, I have not recognized any pattern to make the problem consistently
reproducible.
Comment 1 Frederic Fusier CLA 2005-01-22 10:51:28 EST
Move to JDT/UI.
Please try to find a scenario to reproduce this issue (I never got it after many
tries)... This would help a lot to fix it.
Note that I've tried on WinXP... perhaps a platform issue?
Comment 2 Dirk Baeumer CLA 2005-01-23 09:29:47 EST
Markus, we should try to understand this for 3.1. 

Could be the fact that we fetch the result in background a problem here. 

Frederic, this could also be a search bug since all call hierarchy does is
searching for references.
Comment 3 Frederic Fusier CLA 2005-01-23 10:29:05 EST
I agree, but as far as I know, when there's a JDT/Core problem, search always
fails. So, that's why my first assumption was about an UI issue (JDT or
Platform) as in this case it sometimes works and sometimes does not.
Of course, this assumption might be wrong...
Comment 4 Brian Stiles CLA 2005-01-24 17:09:42 EST
I still haven't been able to determine a consistently reproducable test case. 
However, the comment about the search being run in the background got me to
thinking that I should note that my machine is a dual Xeon with HyperThreading
(shows up as four processors to the system).  If the cause of the problem is due
to thread coordination, it is possible that the problem may only show up on an
SMP machine and may not be reproducable on a non-SMP machine.  That might
explain why you can't reproduce it if you don't happen to have an SMP machine.

I will keep trying to find a consistently reproducable case.
Comment 5 Brian Stiles CLA 2005-01-31 16:50:25 EST
I've had some success reproducing the problem if I call Open Call Hierarchy
repeatedly in rapid succession.  The call is bound to Ctrl+Alt+H.  If I hit the
hot key a few times quickly, I usually end up reproducing the problem.  It
doesn't seem to matter what method I'm selecting, as far as I can tell.  I don't
know for sure that the timing matters, it's just how I have been able to
reproduce it fairly consistently.
Comment 6 Markus Keller CLA 2005-02-01 03:41:34 EST
I can reproduce the problem in I20050126-0800 with steps from comment 5 (rapid
succession of Ctrl+Alt+H). I'll look into this.
Comment 7 Mike Feldman CLA 2005-02-02 12:39:43 EST
I'm not positive I am seeing exactly the same cause of this problem but it seems
that if I have many files open in my workspace, greater than ~18, the call
hierarchy stops working. Searche also fail to provide any results. If I exit
eclipse, delete the workspace, and then import the project again, everything
works. This has happened many times already but at least I know how to get it
working again. 
I'm running version 3.0.1 on RedHat linux 3.0 EL. I hope this helps. 
Comment 8 Markus Keller CLA 2005-05-02 11:28:38 EDT
Mike, your comment 7 does not seem to be related to this bug. If you still see
that  problem, please open a new bug report for it.
Comment 9 Markus Keller CLA 2005-05-27 04:55:57 EDT
I can only reproduce when I manually collapse the node that currently shows the
pending ellipsis. Moving milestone to 3.2 for further investigation.
Comment 10 Brian Stiles CLA 2005-05-27 11:19:58 EDT
I've never manipulated the tree while the search was taking place and the
problem still occurs in 3.1M7.  I just tested with
org.apache.regexp.CharacterIterator.substring(int, int).  The first call to show
the call hierarchy failed, the second succeeded.  Nothing other than waiting for
the results to show occurred during the processing of the call.  Given that
there's no way to know that the call failed and that the penalty is incorrect
information, it seems problematic to defer this.

I for one use this feature heavily to understand how and where a method is being
used before altering or deleting a method.  The effect of this bug (if I didn't
know the feature was broken) is that I might delete or alter in an incompatible
way a method that I thought (incorrectly) had no callers.
Comment 11 Markus Keller CLA 2005-05-27 13:51:50 EDT
I could not reproduce on my single-processor WinXP box. 
I *could* reproduce this about every fifth time on a dual processor Linux-GTK
with these steps:

 1. open java.math.BigInteger
 2. select floatValue()
 3. press Ctrl+Alt+H
 4. repeat 3. until the call hierarchy does not show any children below the root
node. Sometimes, I needed about 20 repetitions, and sometimes, it already failed
at every second try.

This is a concurrency issue with the TreeViewer and/or the
DeferredTreeContentManager. I added printLn statements and verified that the
call hierarchy's DeferredMethodWrapper#fetchDeferredChildren(..) returns the
right children even when they are not shown afterwards.

I set a breakpoint in AbstractTreeViewer#internalRemove(Object[]) inside the
third line of:
if (!getExpanded(parentItem) && getItemCount(parentItem) == 0) {
	// append a dummy if necessary
	if (isExpandable(parentItem.getData())) {
		newItem(parentItem, SWT.NULL, -1);
	} else {
		// XXX: Workaround (PR missing)
		tree.redraw();
	}
}

The children are exactly then not shown, when this breakpoint is hit.

Moving to Platform/UI.
Comment 12 Koen van Dijken CLA 2005-08-28 18:07:13 EDT
I can reliably reproduce something similar on a freshly installed 3.1 (and also
3.2M2) installation.

Open source for org.eclipse.ui.views.properties.PropertySheetViewer
Find callers of activateCellEditor(TreeItem item). It does not find any caller,
although there is (at least) one, in PropertySheetViewer.handleSelect(). This is
on Eclipse 3.1.
Comment 13 Markus Keller CLA 2005-09-08 10:33:01 EDT
Comment 12 is unrelated to this bug. I opened bug 109053.
Comment 14 Steffen Barthel CLA 2005-09-16 08:12:16 EDT
I got methods like 
public String getId(), 
which are often (1049) referenced in workspace, but call hierarchy shows me none.
the call hierarchies of other methods do behave normal.
Reducing the search scope (in the call hierarchy view menu) from workspace to
hierarchy leads to a reasonable call hierarchy.
So a hypothesis might be that there are too many callers of a method in a search
scope.
We are using 3.1 on XP Professional, same reproducable behaviour in two
development environments.
Comment 15 Boris Bokowski CLA 2005-12-13 14:15:11 EST
I wasn't able to reproduce this without collapsing the root node while the results are being calculated (see comment #9). Moving to M5 to fix at least this issue.
Comment 16 Boris Bokowski CLA 2006-02-13 20:26:29 EST
The behaviour described in comment #9 (collapsing a node while its children are being computed) is due to a bug in JDT.

If I add another case to the if statement in CallHierarchyContentProvider.hashChildren() as follows, the bug goes away. I am not sure if this causes the original problem as well, but it would not surprise me:

else if (element instanceof DeferredMethodWrapper) {
        	// Err on the safe side by returning true even though
        	// we don't know for sure that there are children.
        	return true;
        }

Also, while I was looking at the code, I found that whenever you pressed Ctrl-Alt-H, children were computed two times, once for the old root node of the viewer, and once for the new one. This is due to the fact that you call setSorter() before setting the input to the new input in CallHierarchyViewPart.updateView(). Since calling setSorter() causes a refresh, you should set the input to null before you set the sorter, e.g. like this:

            String[] args = new String[] { elementName, scopeDescription};
            // set input to null so that setSorter does not cause a refresh on the old contents
            fCallHierarchyViewer.setInput(null);
			if (fCurrentCallMode == CALL_MODE_CALLERS) {
                setContentDescription(Messages.format(CallHierarchyMessages.CallHierarchyViewPart_callsToMethod, args)); 
                fCallHierarchyViewer.setSorter(new ViewerSorter()); //bug 111423: sort caller hierarchy alphabetically
                fCallHierarchyViewer.setMethodWrapper(getCallerRoot());
            } else {
                setContentDescription(Messages.format(CallHierarchyMessages.CallHierarchyViewPart_callsFromMethod, args)); 
                fCallHierarchyViewer.setSorter(null);
                fCallHierarchyViewer.setMethodWrapper(getCalleeRoot());
            }
Comment 17 Boris Bokowski CLA 2006-02-13 20:28:11 EST
s/hashChildren/hasChildren/ :-)
Comment 18 Markus Keller CLA 2006-02-14 12:06:58 EST
Thanks Boris, I'll look into it again.
Comment 19 Markus Keller CLA 2006-03-28 05:30:00 EST
Boris, I released the fixes you suggested. This solves the problem of missing children, but does not solve the problem that the node is sometimes collapsed on a dual processor machine. However, with the fixes, the user can now expand the node at no additional cost if this happens, so I'll close this bug.

Opened bug 133490 for the remaining (minor) problem.
Comment 20 Benno Baumgartner CLA 2006-03-30 04:07:30 EST
verified in I20060330-0010