Bug 67260 - Refactoring - Rename method throw an AssertionFailedException
Summary: Refactoring - Rename method throw an AssertionFailedException
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M6   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-15 11:10 EDT by David Audel CLA
Modified: 2005-03-24 09:37 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Audel CLA 2004-06-15 11:10:25 EDT
1) create the class String.java
package pack;
public class String {
}
2) create the class X.java
public class X {
  public static void foo(String s) {
  }
  public void foo(pack.String) {
  }
}
3) select the second 'foo' method (foo(pack.String))
4) do Refactor->Rename 
5) change name to 'bar'
6) do OK

an exception occur
org.eclipse.jdt.internal.corext.Assert$AssertionFailedException: assertion 
failed; second condition
	at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:136)
	at 
org.eclipse.jdt.internal.corext.refactoring.rename.RippleMethodFinder.getAllRip
pleMethods(RippleMethodFinder.java:115)
	at 
org.eclipse.jdt.internal.corext.refactoring.rename.RippleMethodFinder.getRelate
dMethods(RippleMethodFinder.java:62)
	at 
org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodProcessor.initia
lizeMethodsToRename(RenameMethodProcessor.java:161)
	at 
org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodProcessor.checkF
inalConditions(RenameMethodProcessor.java:257)
	at 
org.eclipse.jdt.internal.corext.refactoring.rename.RenameVirtualMethodProcessor
.checkFinalConditions(RenameVirtualMethodProcessor.java:91)
	at 
org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring.checkFi
nalConditions(ProcessorBasedRefactoring.java:134)
	at org.eclipse.ltk.core.refactoring.CheckConditionsOperation.run
(CheckConditionsOperation.java:84)
	at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run
(CreateChangeOperation.java:114)
	at org.eclipse.ltk.core.refactoring.PerformChangeOperation.run
(PerformChangeOperation.java:182)
	at org.eclipse.core.internal.resources.Workspace.run
(Workspace.java:1673)
	at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run
(WorkbenchRunnableAdapter.java:58)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run
(ModalContext.java:101)



The problem seems to be inside RippleMethodFinder#declaresAsVirtual(). 
Checks.findSimilarMethod(m, type) return the wrong method (the first method)
Comment 1 Philipe Mulet CLA 2004-06-15 12:51:46 EDT
We discovered this defect when looking into bug 66271. 
It is not revealed by fix for bug 66271, as demonstrated with David's 
testcase, but if we fix 66271, we get further into refactoring and then this 
bug will occur more often. Scenario is rare, but we have to be careful.
Comment 2 Markus Keller CLA 2004-06-16 14:57:00 EDT
The fix for bug 66271 would IMO not introduce more errors in refactorings.
Refactorings which can be started from a code selection of a java element in the
editor can always be started by selecting the java element in e.g. the Package
Explorer as well.

The example in comment 0 reveals a deficiency in the RippleMethodFinder: The RMF
uses IMethod#isSimilar(IMethod method) to find ripple methods in the
hierarchies. Since IMethod#isSimilar(IMethod method) only compares simple names
of the parameters' types, this lookup may fail.

The assertion in RippleMethodFinder is causing more harm than good: It fails in
the only case where the refactoring would work correctly but doesn't find most
of the cases where the current implementation doesn't work correctly.

Rename Method (without the offending assert) is correct if the method to rename
has only "similar" methods declared in the same type. If "similar" methods are
found in the hierarchies, it often renames too many declarations (and their
references).

Concluding, I opt for giving a go for bug 66271 and removing the assertion in
RippleMethodFinder for 3.0. Removing the assertion is a no-risk job.
Consequences of getting more declarations by patch 66271 is low-risk for jdt-ui.
Comment 3 Dirk Baeumer CLA 2004-06-17 09:01:04 EDT
We decided to not fix this for 3.0 since it is too risky and the assert could 
fail since 1.0. It could be triggered using the same test case but executing 
the rename from the outliner.

To get this assertion the code must have 

- overloaded methods
- the simple types names of all parameters of the methods must be the
  same.

I consider this a rare case (that's why we never got a PR for this).
Comment 4 Dirk Baeumer CLA 2005-03-24 06:54:23 EST
Markus, was is the state of this bug ?
Comment 5 Markus Keller CLA 2005-03-24 09:37:02 EST
This has been fixed with the new RippleMethodFinder2.