Bug 83440 NullPointerException in refactoring preview dialog
When refactoring a private member class into a top-level class using "Move Member Type to New File...", in the preview dialog, clicking on the name of the class in the preview (to see the detailed changes), or any member of that class nested under it in the tree, causes a NullPointerException. A test case that fails on my machine: public class TestClass { private class TestClass2 { private String x; private int y; } } Doing TestClass2 -> Refactor -> Move Member Type to New File... -> Preview -> Continue -> Open tree to TestClass2 and selecting it or any member variable causes the following NullPointerException: java.lang.NullPointerException at org.eclipse.ltk.core.refactoring.TextChange.getPreviewContent(TextChange.java:599) at org.eclipse.ltk.internal.ui.refactoring.TextChangePreviewViewer.setInput(TextChangePreviewViewer.java:184) at org.eclipse.ltk.internal.ui.refactoring.PseudoJavaChangeElement.feedInput(PseudoJavaChangeElement.java:73) at org.eclipse.ltk.internal.ui.refactoring.PreviewWizardPage.showPreview(PreviewWizardPage.java:376) at org.eclipse.ltk.internal.ui.refactoring.PreviewWizardPage.access$2(PreviewWizardPage.java:355) at org.eclipse.ltk.internal.ui.refactoring.PreviewWizardPage$2.selectionChanged(PreviewWizardPage.java:346) at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:163) at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1044) at org.eclipse.core.runtime.Platform.run(Platform.java:747) at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:161) at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:1667) at org.eclipse.jface.viewers.StructuredViewer.handleSelect(StructuredViewer.java:935) at org.eclipse.jface.viewers.CheckboxTreeViewer.handleSelect(CheckboxTreeViewer.java:268) at org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected(StructuredViewer.java:961) at org.eclipse.jface.util.OpenStrategy.fireSelectionEvent(OpenStrategy.java:209) at org.eclipse.jface.util.OpenStrategy.access$3(OpenStrategy.java:204) at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:364) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:833) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2803) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2448) at org.eclipse.jface.window.Window.runEventLoop(Window.java:718) at org.eclipse.jface.window.Window.open(Window.java:696) at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation$1.run(RefactoringWizardOpenOperation.java:125) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69) at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation.run(RefactoringWizardOpenOperation.java:138) at org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter.activate(RefactoringStarter.java:40) at org.eclipse.jdt.ui.actions.ConvertNestedToTopAction.startRefactoring(ConvertNestedToTopAction.java:210) at org.eclipse.jdt.ui.actions.ConvertNestedToTopAction.run(ConvertNestedToTopAction.java:166) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:216) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:188) at org.eclipse.jface.action.Action.runWithEvent(Action.java:989) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:555) at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:505) at org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:419) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:833) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2803) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2448) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1569) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1540) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:285) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:144) at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:102) at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:220) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:273) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:129) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.eclipse.core.launcher.Main.basicRun(Main.java:185) at org.eclipse.core.launcher.Main.run(Main.java:710) at org.eclipse.core.launcher.Main.main(Main.java:694)
org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/TextChange.java
import org.eclipse.jface.text.Region;
import org.eclipse.ltk.internal.core.refactoring.Assert;
import org.eclipse.ltk.internal.core.refactoring.Changes;
/**
 * A text change is a special change object that applies a {@link TextEdit
 * text edit tree} to a document. The text change manages the text edit tree. 
 * Access to the document must be provided by concrete subclasses via the method
 * {@link #acquireDocument(IProgressMonitor) aquireDocument}, 
 * {@link #commit(IDocument document, IProgressMonitor pm) commitDocument}, and
 * {@link #releaseDocument(IDocument, IProgressMonitor) releaseDocument}.
 * <p>
 * A text change offers the ability to access the original content of
 * the document as well as creating a preview of the change. The edit
 * tree gets copied when creating any king of preview. Therefore no region
 * updating on the original edit tree takes place when requesting a preview
 * (for more information on region updating see class {@link TextEdit TextEdit}. 
 * If region tracking is required for a preview it can be enabled via a call 
 * to the method {@link #setKeepPreviewEdits(boolean) setKeepPreviewEdits}.
 * If enabled the text change keeps the copied edit tree executed for the
 * preview allowing clients to map an original edit to an executed edit. The
 * executed edit can then be used to determine its position in the preview.
 * </p>
 * <p> 
 * Note: this class is not intended to be subclassed outside the refactoring
 * framework.
 * </p>
 * 
 * @since 3.0
 */
public abstract class TextChange extends Change {