Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 350523 - [hashcode/equals] generate hashCode and equals fails for class with inner class and package-info.java
Summary: [hashcode/equals] generate hashCode and equals fails for class with inner cla...
Status: CLOSED DUPLICATE of bug 348024
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-28 04:22 EDT by Michael Koch CLA
Modified: 2011-07-05 02:43 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Koch CLA 2011-06-28 04:22:57 EDT
Build Identifier: I20110613-1736

The "generate hashCode() and equals()" Source action logs a NullPointerException instead of opening the dialog if (1) the class has an inner class and (2) a package-info.java file exists in the same package.

Here is the exception stack trace:
java.lang.NullPointerException
	at org.eclipse.jdt.internal.corext.dom.ASTNodes.getParent(ASTNodes.java:514)
	at org.eclipse.jdt.ui.actions.GenerateMethodAbstractAction.initialize(GenerateMethodAbstractAction.java:401)
	at org.eclipse.jdt.ui.actions.GenerateHashCodeEqualsAction.initialize(GenerateHashCodeEqualsAction.java:217)
	at org.eclipse.jdt.ui.actions.GenerateMethodAbstractAction.run(GenerateMethodAbstractAction.java:230)
	at org.eclipse.jdt.ui.actions.GenerateMethodAbstractAction.checkAndRun(GenerateMethodAbstractAction.java:218)
	at org.eclipse.jdt.ui.actions.GenerateMethodAbstractAction.run(GenerateMethodAbstractAction.java:176)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:279)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:251)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
	at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
	at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
	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:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	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.equinox.launcher.Main.invokeFramework(Main.java:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)

Reproducible: Always

Steps to Reproduce:
1. Create a new package "foo"
2. Create a package-info.java file in this package. The file needs only contain the package declaration.
3. Create a class file "Foo.java" in the package with this content:
package foo;

public class Foo {

	private static class Bar {
	}

	private String baz;

}

4. Select "Source > Generate hashCode() and equals()" from the context menu.

Instead of showing the dialog, the exception is added to the error log.
Comment 1 Doug Simon CLA 2011-07-04 05:05:28 EDT
This issue also applies to renaming (and probably to other refactorings). When I try to rename a local variable in a class in a package where there is a package-info, I get a very similar exception:

Caused by: java.lang.NullPointerException
	at org.eclipse.jdt.internal.corext.dom.ASTNodes.getParent(ASTNodes.java:514)
	at org.eclipse.jdt.internal.corext.refactoring.rename.RefactoringAnalyzeUtil.getBlock(RefactoringAnalyzeUtil.java:74)
	at org.eclipse.jdt.internal.corext.refactoring.rename.RenameAnalyzeUtil.getEnclosingBlockOrMethod(RenameAnalyzeUtil.java:456)
	at org.eclipse.jdt.internal.corext.refactoring.rename.RenameAnalyzeUtil.analyzeLocalRenames(RenameAnalyzeUtil.java:427)
	at org.eclipse.jdt.internal.corext.refactoring.rename.RenameLocalVariableProcessor.doCheckFinalConditions(RenameLocalVariableProcessor.java:273)
	at org.eclipse.jdt.internal.corext.refactoring.rename.JavaRenameProcessor.checkFinalConditions(JavaRenameProcessor.java:48)
	at org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring.checkFinalConditions(ProcessorBasedRefactoring.java:224)
	at org.eclipse.ltk.core.refactoring.Refactoring.checkAllConditions(Refactoring.java:160)
	at org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper$Operation.run(RefactoringExecutionHelper.java:80)
	at org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:39)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:728)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
	at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:4860)
	at org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:106)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)

If I delete the package-info.java file, the problem goes away.
Comment 2 Doug Simon CLA 2011-07-04 05:08:17 EDT
I forgot to mention this happens on Linux x64. Here's my session data from the error log:

eclipse.buildId=I20110613-1736
java.version=1.6.0_22
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Command-line arguments:  -data /mnt/ubuntu-10.04/home/dsimon/maxine-cache -os linux -ws gtk -arch x86_64
Comment 3 Dani Megert CLA 2011-07-05 02:43:58 EDT
Probably caused by same problem as bug 348024.

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