Project: JDT
Bug 133818 NPE when creating a new JUnit test
Reported: 2006-03-29 07:45:38 | Status: verified fixed

This bug happens on Windows XP and Mac OSX on 3.2M5a. Steps to reproduce: 1. right click a class and select 'New JUnit Test case' 2. fill in first page 3. Click next to go to second page 4. Select Objects constructor Object.Object() (any of Object's methods would do) 5. Check 'Create tasks for generated test methods' 6. Click finish The error below is generated, and an empty file is created for the new test which you need to delete before trying again. Stack: java.lang.reflect.InvocationTargetException at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:371) at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:305) at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java:833) at org.eclipse.ui.internal.progress.ProgressManager$5.run(ProgressManager.java:1094) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69) at org.eclipse.ui.internal.progress.ProgressManager.runInUI(ProgressManager.java:1090) at org.eclipse.jdt.internal.junit.wizards.JUnitWizard.finishPage(JUnitWizard.java:66) at org.eclipse.jdt.internal.junit.wizards.NewTestCaseCreationWizard.performFinish(NewTestCaseCreationWizard.java:56) at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:666) at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:349) at org.eclipse.jface.dialogs.Dialog$3.widgetSelected(Dialog.java:645) at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:90) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:925) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3287) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2907) at org.eclipse.jface.window.Window.runEventLoop(Window.java:811) at org.eclipse.jface.window.Window.open(Window.java:789) at org.eclipse.ui.internal.actions.NewWizardShortcutAction.run(NewWizardShortcutAction.java:110) at org.eclipse.jface.action.Action.runWithEvent(Action.java:492) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:530) at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:480) at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:392) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:925) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3287) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2907) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1899) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1863) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:417) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:143) at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:106) at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:99) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:92) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:68) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:374) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:169) 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:324) at org.eclipse.core.launcher.Main.invokeFramework(Main.java:338) at org.eclipse.core.launcher.Main.basicRun(Main.java:282) at org.eclipse.core.launcher.Main.run(Main.java:977) at org.eclipse.core.launcher.Main.main(Main.java:952) Caused by: java.lang.NullPointerException at org.eclipse.jdt.ui.CodeGeneration.getMethodBodyContent(CodeGeneration.java:315) at org.eclipse.jdt.junit.wizards.NewTestCaseWizardPageOne.appendTestMethodBody(NewTestCaseWizardPageOne.java:701) at org.eclipse.jdt.junit.wizards.NewTestCaseWizardPageOne.createTestMethodStubs(NewTestCaseWizardPageOne.java:665) at org.eclipse.jdt.junit.wizards.NewTestCaseWizardPageOne.createTypeMembers(NewTestCaseWizardPageOne.java:486) at org.eclipse.jdt.ui.wizards.NewTypeWizardPage.createType(NewTypeWizardPage.java:2007) at org.eclipse.jdt.ui.wizards.NewTypeWizardPage$7.run(NewTypeWizardPage.java:2479) at org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation.execute(WorkspaceModifyDelegatingOperation.java:68) at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:100) at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1733) at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:112) at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:360) ... 44 more

Files changed in fix:
org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/wizards/NewTestCaseWizardPageOne.java org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/wizards/NewTestCaseWizardPageTwo.java