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
*       of surrounding lines is added. The value of <code>surroundingLines
	 *       </code> is only considered if <code>expandRegionToFullLine</code>
	 *       is <code>true</code>
	 *   </li>
	 * </ul> 
	 * 
	 * @param changeGroups a set of change groups for which a preview is to be
	 *  generated
	 * @param region the starting region for the clipping
	 * @param expandRegionToFullLine if <code>true</code> is passed the region
	 *  is extended to cover full lines
	 * @param surroundingLines the number of surrounding lines to be added to 
	 *  the clipping region. Is only considered if <code>expandRegionToFullLine
	 *  </code> is <code>true</code>
	 * @param pm a progress monitor to report progress or <code>null</code>
	 *  if no progress reporting is desired
	 * 
	 * @return the current content of the text change clipped to a region
	 *  determined by the given parameters.
	 * 
	 * @throws CoreException if an exception occurs while generating the preview
	 * 
	 * @see #getCurrentContent(IRegion, boolean, int, IProgressMonitor)
	 */
	public String getPreviewContent(TextEditChangeGroup[] changeGroups, IRegion region, boolean expandRegionToFullLine, int surroundingLines, IProgressMonitor pm) throws CoreException {
		IRegion currentRegion= getRegion(changeGroups);
		Assert.isTrue(region.getOffset() <= currentRegion.getOffset() && 
			currentRegion.getOffset() + currentRegion.getLength() <= region.getOffset() + region.getLength());
		PreviewAndRegion result= getPreviewDocument(changeGroups, pm);
		int delta= result.region.getLength() - currentRegion.getLength();