Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 313308 - [extract method] NPE during extract method refactoring
Summary: [extract method] NPE during extract method refactoring
Status: CLOSED DUPLICATE of bug 312867
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.6   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-18 05:47 EDT by Ulli Hafner CLA
Modified: 2010-05-18 09:20 EDT (History)
2 users (show)

See Also:


Attachments
File that causes the exception (4.46 KB, text/plain)
2010-05-18 05:54 EDT, Ulli Hafner CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ulli Hafner CLA 2010-05-18 05:47:09 EDT
What steps will reproduce the problem?
0. Change text and don't save file
1. Select text block	
2. Run 'Extract Method Refactoring'
3. Enter method name
4. Press 'Finish'
5. Exception is raised


-- Error Details --
Date: Tue May 18 11:41:31 CEST 2010
Message: Internal Error
Severity: Error
Product: Eclipse SDK 3.6.0.v201004291549 (org.eclipse.sdk.ide)
Plugin: org.eclipse.ltk.ui.refactoring
Session Data:
eclipse.buildId=I20100429-1549
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.ui.actions.ExtractMethodAction.run(ExtractMethodAction.java:87)
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:8153)
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:2214)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3157)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2601)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2565)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2399)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:669)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:662)
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.NullPointerException
at org.eclipse.jdt.internal.corext.refactoring.util.SelectionAwareSourceRangeComputer.initializeRanges(SelectionAwareSourceRangeComputer.java:94)
at org.eclipse.jdt.internal.corext.refactoring.util.SelectionAwareSourceRangeComputer.computeSourceRange(SelectionAwareSourceRangeComputer.java:47)
at org.eclipse.jdt.internal.core.dom.rewrite.RewriteEventStore$NodeRangeInfo.updatePlaceholderSourceRanges(RewriteEventStore.java:189)
at org.eclipse.jdt.internal.core.dom.rewrite.RewriteEventStore.processListWithRanges(RewriteEventStore.java:756)
at org.eclipse.jdt.internal.core.dom.rewrite.RewriteEventStore.prepareNodeRangeCopies(RewriteEventStore.java:737)
at org.eclipse.jdt.internal.core.dom.rewrite.RewriteEventStore.prepareMovedNodes(RewriteEventStore.java:686)
at org.eclipse.jdt.core.dom.rewrite.ASTRewrite.internalRewriteAST(ASTRewrite.java:268)
at org.eclipse.jdt.core.dom.rewrite.ASTRewrite.rewriteAST(ASTRewrite.java:260)
at org.eclipse.jdt.internal.corext.refactoring.code.ExtractMethodRefactoring.createChange(ExtractMethodRefactoring.java:531)
at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:124)
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.NullPointerException
at org.eclipse.jdt.internal.corext.refactoring.util.SelectionAwareSourceRangeComputer.initializeRanges(SelectionAwareSourceRangeComputer.java:94)
at org.eclipse.jdt.internal.corext.refactoring.util.SelectionAwareSourceRangeComputer.computeSourceRange(SelectionAwareSourceRangeComputer.java:47)
at org.eclipse.jdt.internal.core.dom.rewrite.RewriteEventStore$NodeRangeInfo.updatePlaceholderSourceRanges(RewriteEventStore.java:189)
at org.eclipse.jdt.internal.core.dom.rewrite.RewriteEventStore.processListWithRanges(RewriteEventStore.java:756)
at org.eclipse.jdt.internal.core.dom.rewrite.RewriteEventStore.prepareNodeRangeCopies(RewriteEventStore.java:737)
at org.eclipse.jdt.internal.core.dom.rewrite.RewriteEventStore.prepareMovedNodes(RewriteEventStore.java:686)
at org.eclipse.jdt.core.dom.rewrite.ASTRewrite.internalRewriteAST(ASTRewrite.java:268)
at org.eclipse.jdt.core.dom.rewrite.ASTRewrite.rewriteAST(ASTRewrite.java:260)
at org.eclipse.jdt.internal.corext.refactoring.code.ExtractMethodRefactoring.createChange(ExtractMethodRefactoring.java:531)
at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:124)
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-18 05:54:48 EDT
Created attachment 168886 [details]
File that causes the exception
Comment 2 Ulli Hafner CLA 2010-05-18 05:56:22 EDT
Here is the selection that I used for the extract method refactoring:

        SashForm leftVerticalSash = new SashForm(horizontalSash, SWT.VERTICAL);
        leftVerticalSash.setLayout(new FillLayout());

        NavigationGraph graph = new NavigationGraph(model);
        focusControl = graph.createControl(leftVerticalSash);

        ClausesModel resultsModel = new ClausesModel(model.getOntology(), model.getAxiomMapper());
        ClausesComponent resultsComponent = new ClausesComponent(resultsModel);
        resultsComponent.createControls(leftVerticalSash);

        leftVerticalSash.setWeights(new int[] {60, 40}); // NOCHECKSTYLE
Comment 3 Frederic Fusier CLA 2010-05-18 09:18:16 EDT
I can reproduce with HEAD. No need to change the text, get the CU from
comment 1, select the lines of comment 2 and try to extract a method --> NPE

Move to JDT/UI as the problem is located in SelectionAwareSourceRangeComputer.initializeRanges() which set the field fDocumentPortionToScan to null when entering but use it after at line 94 where the NPE occurs
Comment 4 Dani Megert CLA 2010-05-18 09:20:14 EDT

*** This bug has been marked as a duplicate of bug 312867 ***