Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 314407

Summary: [inline] IndexOutOfBoundsException in inline method refactoring with compile error
Product: [Eclipse Project] JDT Reporter: Ulli Hafner <Knut.Friedhelm>
Component: UIAssignee: Deepak Azad <deepakazad>
Status: VERIFIED FIXED QA Contact:
Severity: minor    
Priority: P3 CC: daniel_megert, markus.kell.r, Olivier_Thomann, rthakkar
Version: 3.6   
Target Milestone: 3.7 M2   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
The file that caused the exception
none
Test case.
none
fix+tests none

Description Ulli Hafner CLA 2010-05-26 04:10:58 EDT
What steps will reproduce the problem?
1. Edit the attached file (it has compile errors)
2. Selected getImage() in line 31
3. Select Inline Method Refactoring
4. Select Replace all invocations
5. Error occurs
6. After saving the file, the error still remains

-- Error Details --
Date: Wed May 26 09:58:21 CEST 2010
Message: Internal Error
Severity: Error
Product: Eclipse SDK 3.6.0.v201005201744 (org.eclipse.sdk.ide)
Plugin: org.eclipse.ltk.ui.refactoring
Session Data:
eclipse.buildId=I20100520-1744
java.version=1.6.0_20
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=linux, ARCH=x86, WS=gtk, NL=en_US
Framework arguments:  --launcher.XXMaxPermSize=256m
Command-line arguments:  -os linux -ws gtk -arch x86 -debug /home/hafner/Documents/eclipse.debug -data /home/hafner/Workspaces/Faktor-Logik --launcher.XXMaxPermSize=256m


Exception Stack Trace:
java.lang.reflect.InvocationTargetException
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:421)
at org.eclipse.ltk.internal.ui.refactoring.RefactoringWizardDialog2.run(RefactoringWizardDialog2.java:330)
at org.eclipse.ltk.ui.refactoring.RefactoringWizard.internalPerformFinish(RefactoringWizard.java:573)
at org.eclipse.ltk.ui.refactoring.UserInputWizardPage.performFinish(UserInputWizardPage.java:153)
at org.eclipse.ltk.ui.refactoring.RefactoringWizard.performFinish(RefactoringWizard.java:646)
at org.eclipse.ltk.internal.ui.refactoring.RefactoringWizardDialog2.okPressed(RefactoringWizardDialog2.java:454)
at org.eclipse.jface.dialogs.Dialog.buttonPressed(Dialog.java:472)
at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:624)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:234)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1234)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3540)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3159)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
at org.eclipse.jface.window.Window.open(Window.java:801)
at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation$1.run(RefactoringWizardOpenOperation.java:180)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation.run(RefactoringWizardOpenOperation.java:192)
at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation.run(RefactoringWizardOpenOperation.java:115)
at org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter.activate(RefactoringStarter.java:38)
at org.eclipse.jdt.internal.corext.refactoring.RefactoringExecutionStarter.startInlineMethodRefactoring(RefactoringExecutionStarter.java:330)
at org.eclipse.jdt.internal.ui.refactoring.actions.InlineMethodAction.tryInlineMethod(InlineMethodAction.java:143)
at org.eclipse.jdt.ui.actions.InlineAction.run(InlineAction.java:122)
at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:278)
at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:250)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
at org.eclipse.ui.commands.ActionHandler.execute(ActionHandler.java:185)
at org.eclipse.ui.internal.handlers.LegacyHandlerWrapper.execute(LegacyHandlerWrapper.java:109)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyboard.java:468)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:786)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:885)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:567)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.java:508)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(WorkbenchKeyboard.java:123)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1525)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1233)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1243)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1270)
at org.eclipse.swt.widgets.Widget.gtk_key_press_event(Widget.java:729)
at org.eclipse.swt.widgets.Control.gtk_key_press_event(Control.java:2833)
at org.eclipse.swt.widgets.Composite.gtk_key_press_event(Composite.java:707)
at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:1719)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4783)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4358)
at org.eclipse.swt.internal.gtk.OS._gtk_main_do_event(Native Method)
at org.eclipse.swt.internal.gtk.OS.gtk_main_do_event(OS.java:8163)
at org.eclipse.swt.widgets.Display.eventProc(Display.java:1239)
at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native Method)
at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(OS.java:2224)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3157)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2629)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2427)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:663)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at org.eclipse.jdt.core.dom.ASTNode$NodeList.get(ASTNode.java:1211)
at org.eclipse.jdt.internal.corext.refactoring.code.SourceProvider.getParameterData(SourceProvider.java:301)
at org.eclipse.jdt.internal.corext.refactoring.code.CallInliner.computeRealArguments(CallInliner.java:507)
at org.eclipse.jdt.internal.corext.refactoring.code.CallInliner.initialize(CallInliner.java:290)
at org.eclipse.jdt.internal.corext.refactoring.code.InlineMethodRefactoring.checkFinalConditions(InlineMethodRefactoring.java:306)
at org.eclipse.ltk.core.refactoring.CheckConditionsOperation.run(CheckConditionsOperation.java:85)
at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:121)
at org.eclipse.ltk.core.refactoring.PerformChangeOperation.run(PerformChangeOperation.java:209)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Root exception:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at org.eclipse.jdt.core.dom.ASTNode$NodeList.get(ASTNode.java:1211)
at org.eclipse.jdt.internal.corext.refactoring.code.SourceProvider.getParameterData(SourceProvider.java:301)
at org.eclipse.jdt.internal.corext.refactoring.code.CallInliner.computeRealArguments(CallInliner.java:507)
at org.eclipse.jdt.internal.corext.refactoring.code.CallInliner.initialize(CallInliner.java:290)
at org.eclipse.jdt.internal.corext.refactoring.code.InlineMethodRefactoring.checkFinalConditions(InlineMethodRefactoring.java:306)
at org.eclipse.ltk.core.refactoring.CheckConditionsOperation.run(CheckConditionsOperation.java:85)
at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:121)
at org.eclipse.ltk.core.refactoring.PerformChangeOperation.run(PerformChangeOperation.java:209)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Comment 1 Ulli Hafner CLA 2010-05-26 04:11:42 EDT
Created attachment 169941 [details]
The file that caused the exception
Comment 2 Olivier Thomann CLA 2010-05-26 10:00:31 EDT
Could you please provide a small project that contains the attached file + all required files that are needed to be able to use the inline refactoring?
As is I cannot invoke the refactoring as the cu contains too many compile errors for types that cannot be resolved.
Comment 3 Olivier Thomann CLA 2010-05-26 10:07:10 EDT
I reproduced it if the only compile error is related to the line:
        return getImage(node.hasUnknownAxioms(property));
Comment 4 Olivier Thomann CLA 2010-05-26 10:28:15 EDT
Moving to JDT/UI. I'll attach a zipped project to reproduce the issue.
Comment 5 Olivier Thomann CLA 2010-05-26 10:29:28 EDT
Created attachment 170003 [details]
Test case.

Import the zipped file as an existing project inside an archive file.
Comment 6 Markus Keller CLA 2010-05-28 09:21:18 EDT
Easier example to reproduce (inline getImage()):

public class Try {
    Object getImage() {
	return null;
    }
    
    Object foo() {
	Object o= getImage();
	return getImage(o); 
    }
}
Comment 7 Deepak Azad CLA 2010-07-21 06:47:20 EDT
Create the following 2 classes in different files and inline getImage(), Select "All Invocations" 
=> Invocation with error  in Try is inlined but the one in A is not. This is inconsistent behavior!

public class Try {
    Object getImage(Object o) {
    	return null;
    }

    Object foo() {
    	Object o= getImage();
    	return getImage(o); 
    }
}

class A {
	void foo() {
		new Try().getImage();
	}
}

Reason : The Java search in TargetProvider.MemberTypeTargetProvider.getAffectedCompilationUnits(...) does not matches invocations with compile errors. The invocations with compile errors get added later on using TargetProvider.InvocationFinder, because invocation with compilation error has the same method binding as the declared method but no indication that there is a compilation error.

I really think that JDT core should indicate the presence of an error on a method invocation. The current API does not do that and according to me that is incorrect.
Comment 8 Deepak Azad CLA 2010-08-08 08:08:28 EDT
Created attachment 176108 [details]
fix+tests

Fixed in HEAD.

A method invocation with a compile error has type binding as null. I could use this information to exclude invocations with errors.
Comment 9 Deepak Azad CLA 2010-08-08 08:09:08 EDT
.
Comment 10 Dani Megert CLA 2010-09-14 09:45:38 EDT
Verified in I20100914-0100.
Comment 11 Rajesh CLA 2010-09-14 12:22:43 EDT
Verified for 3.7 M2 with I20100913-1800.