Bug 12525 NPE in extract method
in junit.awtui.TestRunner in the method createUI try to extract the following range: Panel numbersPanel= <START>new Panel(new FlowLayout()); numbersPanel.add(new Label("Runs:")); numbersPanel.add(fNumberOfRuns); numbersPanel.add(new Label(" Errors:")); numbersPanel.add(fNumberOfErrors); numbersPanel.add(new Label(" Failures:")); numbersPanel.add (fNumberOfFailures); <END> You get a walkback: java.lang.NullPointerException at org.eclipse.jdt.internal.corext.dom.SelectionAnalyzer.handleNextSelectedNode (SelectionAnalyzer.java:97) at org.eclipse.jdt.internal.corext.refactoring.code.ExtractMethodAnalyzer.handleNex tSelectedNode(ExtractMethodAnalyzer.java:384) at org.eclipse.jdt.internal.corext.dom.SelectionAnalyzer.visitNode (SelectionAnalyzer.java:73) at org.eclipse.jdt.internal.corext.dom.GenericVisitor.visit (GenericVisitor.java:83) at org.eclipse.jdt.core.dom.ExpressionStatement.accept0 (ExpressionStatement.java:71) at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:986) at org.eclipse.jdt.core.dom.Block.accept0(Block.java:73) at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:957) at org.eclipse.jdt.core.dom.MethodDeclaration.accept0 (MethodDeclaration.java:173) at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:986) at org.eclipse.jdt.core.dom.TypeDeclaration.accept0 (TypeDeclaration.java:153) at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:986) at org.eclipse.jdt.core.dom.CompilationUnit.accept0 (CompilationUnit.java:138) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:906) at org.eclipse.jdt.internal.corext.refactoring.code.ExtractMethodRefactoring.checkA ctivation(ExtractMethodRefactoring.java:161) at org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter.activate (RefactoringStarter.java:74) at org.eclipse.jdt.internal.ui.refactoring.actions.TextSelectionBasedRefactoringAct ion.run(TextSelectionBasedRefactoringAction.java:28) at org.eclipse.jdt.internal.ui.refactoring.actions.TextSelectionAction.run (TextSelectionAction.java:80) at org.eclipse.ui.internal.PluginAction.runWithEvent (PluginAction.java:204) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection (ActionContributionItem.java:407) at org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent (ActionContributionItem.java(Compiled Code)) at org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent (ActionContributionItem.java(Compiled Code)) at org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent (ActionContributionItem.java(Compiled Code)) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java (Compiled Code)) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java(Compiled Code)) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java (Compiled Code)) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java (Compiled Code)) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java (Compiled Code)) at org.eclipse.ui.internal.Workbench.run(Workbench.java:705) at org.eclipse.core.internal.boot.InternalBootLoader.run (InternalBootLoader.java:777) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:319) at java.lang.reflect.Method.invoke(Native Method) at org.eclipse.core.launcher.Main.basicRun(Main.java:196) at org.eclipse.core.launcher.Main.run(Main.java:555) at org.eclipse.core.launcher.UIMain.main(UIMain.java:52)
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/packageview/PackageExplorerPart.java
ISelection newSelection= new StructuredSelection(element);
			if (!fViewer.getSelection().equals(newSelection)) {
				try {
					fViewer.removeSelectionChangedListener(fSelectionListener);
					fViewer.setSelection(newSelection);
				} finally {
					fViewer.addSelectionChangedListener(fSelectionListener);
				}
			}
		}
	}
	
	/**
	 * A compilation unit or class was expanded, expand
	 * the main type.  
	 */
	void expandMainType(Object element) {
		try {
			IType type= null;
			if (element instanceof ICompilationUnit) {
				ICompilationUnit cu= (ICompilationUnit)element;
				IType[] types= cu.getTypes();
				if (types.length > 0)
					type= types[0];
			}
			else if (element instanceof IClassFile) {
				IClassFile cf= (IClassFile)element;
				type= cf.getType();
			}			
			if (type != null) {