Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 362633

Summary: NPE while trying to rename a class
Product: [Eclipse Project] JDT Reporter: Peter Severin <peter>
Component: CoreAssignee: Satyam Kandula <satyam.kandula>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, dev, jarthana, mauromol, satyam.kandula, thauerboeck
Version: 3.8   
Target Milestone: 3.8 M6   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Full stacktrace
none
Proposed patch
none
Class files leading to the NPE none

Description Peter Severin CLA 2011-11-02 03:17:31 EDT
Build Identifier: 20110916-0149

I encounter an NPE when renaming one specific class. Here's the relevant stacktrace:


java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding$3.compare(ReferenceBinding.java:58)
	at java.util.Arrays.mergeSort(Arrays.java:1270)
	at java.util.Arrays.mergeSort(Arrays.java:1281)
	at java.util.Arrays.mergeSort(Arrays.java:1282)
	at java.util.Arrays.sort(Arrays.java:1251)
	at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.sortMethods(ReferenceBinding.java:159)
	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.availableMethods(BinaryTypeBinding.java:254)
	at org.eclipse.jdt.internal.core.search.matching.ClassFileMatchLocator.locateMatches(ClassFileMatchLocator.java:197)

Find the full stacktrace in the attachment. 

Reproducible: Always
Comment 1 Peter Severin CLA 2011-11-02 03:18:24 EDT
Created attachment 206313 [details]
Full stacktrace
Comment 2 Ayushman Jain CLA 2011-11-02 04:23:30 EDT
Is it possible to provide the class, or a minimal reproducible test case? A null check added at that place seems like a fix to be considered but I want to know if its not hiding another root problem.
Comment 3 Peter Severin CLA 2011-11-02 04:35:37 EDT
I am not sure I can provide the code but the class is just an utility class with 3 static methods (no method overloading).

After playing around with this I can see the following pattern:
 * At first the class was named "Utils" and I couldn't rename it.
 * After renaming it manually to something else the rename refactoring started to work again
 * Then I tried to rename it back to "Utils" - it worked
 * But now renaming it to something else causes the NPE again

So it might be because of the class name. There are a dozen of other classes named "Utils" in the workspace.
Comment 4 Satyam Kandula CLA 2011-11-02 06:28:04 EDT
It seems to be having a problem while processing a class file. Getting some more information could help. Could you please try to turn on the debug options and  give the output. 

Create a file called .options in the eclipse folder with the following lines
######
org.eclipse.jdt.core/debug=true
org.eclipse.jdt.core/debug/search=true
######
Then run eclipse as
%eclipsec.exe -debug
Please give the output of the command. Please also attach the file
.metadata/.log located in your workspace.
Comment 5 Satyam Kandula CLA 2011-11-04 06:17:06 EDT
Peter, Thanks for the logs. Unfortunately, I couldn't infer much from the logs. 

bug 250958 has a similar call stack and I think this should have fixed this. Can you please look at the JDT/Core version that you are using?
Comment 6 Satyam Kandula CLA 2011-11-04 06:22:55 EDT
Look for the exact plugin version for org.eclipse.jdt.core.
Comment 7 Peter Severin CLA 2011-11-04 06:30:27 EDT
I have this problem both with Eclipse 3.6 and with the latest 3.7.1. The JDT Core version is 3.7.1.v_B76_R37x.
Comment 8 Satyam Kandula CLA 2011-11-07 00:52:07 EST
There seems to be some problem while processing some class file. However, I am not able to identify the class file that is causing the problem. I think this should be with some jre class. I have tried with some jdks but I could not reproduce the behaviour. 
Can you please give the JDK version you are using?
Comment 9 Peter Severin CLA 2011-11-07 00:54:43 EST
Here you go:

java version "1.6.0_25"
Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.0-b11, mixed mode)
Comment 10 Satyam Kandula CLA 2011-11-23 08:31:04 EST
(In reply to comment #9)
> Here you go:
> 
> java version "1.6.0_25"
> Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
> Java HotSpot(TM) 64-Bit Server VM (build 20.0-b11, mixed mode)
Tried with the exact build, but still unable to reproduce the problem :(. Will it be possible for you to give me h2-1.3.159.jar?
Comment 11 Satyam Kandula CLA 2011-11-25 05:31:33 EST
Thanks for sending the jar. Unfortunately I could not find any problem with this jar. I will need more help from you to debug this. 
- Can you try with a different JRE? 
- Can you debug and help me find the class file that is causing problems? 
- If 2nd is difficult for you, I can give you a debug jdt.core.jar which can print more info.
Comment 12 Mauro Molinari CLA 2011-12-01 11:59:45 EST
I've also hit this problem with the following stack trace:

java.lang.reflect.InvocationTargetException
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:421)
	at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java:1029)
	at org.eclipse.ltk.ui.refactoring.RefactoringWizard.internalPerformFinish(RefactoringWizard.java:605)
	at org.eclipse.ltk.ui.refactoring.UserInputWizardPage.performFinish(UserInputWizardPage.java:153)
	at org.eclipse.jdt.internal.ui.refactoring.PullUpMethodPage.performFinish(PullUpMethodPage.java:507)
	at org.eclipse.ltk.ui.refactoring.RefactoringWizard.performFinish(RefactoringWizard.java:678)
	at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:827)
	at org.eclipse.ltk.internal.ui.refactoring.RefactoringWizardDialog.finishPressed(RefactoringWizardDialog.java:108)
	at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:432)
	at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:624)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:240)
	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.jface.window.Window.runEventLoop(Window.java:825)
	at org.eclipse.jface.window.Window.open(Window.java:801)
	at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation$1.run(RefactoringWizardOpenOperation.java:181)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation.run(RefactoringWizardOpenOperation.java:193)
	at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation.run(RefactoringWizardOpenOperation.java:116)
	at org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter.activate(RefactoringStarter.java:38)
	at org.eclipse.jdt.internal.corext.refactoring.RefactoringExecutionStarter.startExtractSupertypeRefactoring(RefactoringExecutionStarter.java:303)
	at org.eclipse.jdt.internal.ui.actions.ExtractSuperClassAction.run(ExtractSuperClassAction.java:162)
	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)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Caused by: java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding$3.compare(ReferenceBinding.java:58)
	at java.util.Arrays.mergeSort(Unknown Source)
	at java.util.Arrays.mergeSort(Unknown Source)
	at java.util.Arrays.mergeSort(Unknown Source)
	at java.util.Arrays.mergeSort(Unknown Source)
	at java.util.Arrays.sort(Unknown Source)
	at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.sortMethods(ReferenceBinding.java:159)
	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.availableMethods(BinaryTypeBinding.java:259)
	at org.eclipse.jdt.internal.core.search.matching.ClassFileMatchLocator.locateMatches(ClassFileMatchLocator.java:197)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.process(MatchLocator.java:1693)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1099)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1156)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1288)
	at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:94)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:231)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:515)
	at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:592)
	at org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine2.searchPattern(RefactoringSearchEngine2.java:498)
	at org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor.adjustVisibility(MemberVisibilityAdjustor.java:721)
	at org.eclipse.jdt.internal.corext.refactoring.structure.PullUpRefactoringProcessor.createChangeManager(PullUpRefactoringProcessor.java:1149)
	at org.eclipse.jdt.internal.corext.refactoring.structure.PullUpRefactoringProcessor.checkFinalConditions(PullUpRefactoringProcessor.java:765)
	at org.eclipse.jdt.internal.corext.refactoring.structure.ExtractSupertypeProcessor.checkFinalConditions(ExtractSupertypeProcessor.java:246)
	at org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring.checkFinalConditions(ProcessorBasedRefactoring.java:224)
	at org.eclipse.ltk.core.refactoring.CheckConditionsOperation.run(CheckConditionsOperation.java:85)
	at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:121)
	at org.eclipse.ltk.core.refactoring.PerformChangeOperation.run(PerformChangeOperation.java:209)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
	at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Root exception:
java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding$3.compare(ReferenceBinding.java:58)
	at java.util.Arrays.mergeSort(Unknown Source)
	at java.util.Arrays.mergeSort(Unknown Source)
	at java.util.Arrays.mergeSort(Unknown Source)
	at java.util.Arrays.mergeSort(Unknown Source)
	at java.util.Arrays.sort(Unknown Source)
	at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.sortMethods(ReferenceBinding.java:159)
	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.availableMethods(BinaryTypeBinding.java:259)
	at org.eclipse.jdt.internal.core.search.matching.ClassFileMatchLocator.locateMatches(ClassFileMatchLocator.java:197)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.process(MatchLocator.java:1693)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1099)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1156)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1288)
	at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:94)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:231)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:515)
	at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:592)
	at org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine2.searchPattern(RefactoringSearchEngine2.java:498)
	at org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor.adjustVisibility(MemberVisibilityAdjustor.java:721)
	at org.eclipse.jdt.internal.corext.refactoring.structure.PullUpRefactoringProcessor.createChangeManager(PullUpRefactoringProcessor.java:1149)
	at org.eclipse.jdt.internal.corext.refactoring.structure.PullUpRefactoringProcessor.checkFinalConditions(PullUpRefactoringProcessor.java:765)
	at org.eclipse.jdt.internal.corext.refactoring.structure.ExtractSupertypeProcessor.checkFinalConditions(ExtractSupertypeProcessor.java:246)
	at org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring.checkFinalConditions(ProcessorBasedRefactoring.java:224)
	at org.eclipse.ltk.core.refactoring.CheckConditionsOperation.run(CheckConditionsOperation.java:85)
	at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:121)
	at org.eclipse.ltk.core.refactoring.PerformChangeOperation.run(PerformChangeOperation.java:209)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
	at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)

I was trying to extract a superclass from a class.
Unfortunately, the project I'm working with is huge and I can't extract a test case.

The JRE I'm using is 1.6.0_22.
I too have H2 JAR in the build path, but it's version 1.2.139.
Comment 13 Nicolas Cabanis CLA 2011-12-28 09:51:07 EST
I have the same NPE.
I start a headless Eclipse (3.7.1), create a new Java project, set the classpath to include a large set of class files and then call IJavaProject.newTypeHierarchy with a special type.

java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding$3.compare(ReferenceBinding.java:58)
	at java.util.Arrays.mergeSort(Arrays.java:1270)
	at java.util.Arrays.mergeSort(Arrays.java:1282)
	at java.util.Arrays.mergeSort(Arrays.java:1281)
	at java.util.Arrays.mergeSort(Arrays.java:1281)
	at java.util.Arrays.mergeSort(Arrays.java:1281)
	at java.util.Arrays.sort(Arrays.java:1251)
	at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.sortMethods(ReferenceBinding.java:159)
	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.getMethods(BinaryTypeBinding.java:933)
	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.findMethod(BinaryTypeBinding.java:760)
	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.cachePartsFrom(BinaryTypeBinding.java:319)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createBinaryTypeFrom(LookupEnvironment.java:688)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.cacheBinaryType(LookupEnvironment.java:192)
	at org.eclipse.jdt.internal.core.hierarchy.HierarchyResolver.resolve(HierarchyResolver.java:718)
	at org.eclipse.jdt.internal.core.hierarchy.RegionBasedHierarchyBuilder.createTypeHierarchyBasedOnRegion(RegionBasedHierarchyBuilder.java:90)
	at org.eclipse.jdt.internal.core.hierarchy.RegionBasedHierarchyBuilder.build(RegionBasedHierarchyBuilder.java:59)
	at org.eclipse.jdt.internal.core.hierarchy.RegionBasedTypeHierarchy.compute(RegionBasedTypeHierarchy.java:97)
	at org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy.refresh(TypeHierarchy.java:1263)
	at org.eclipse.jdt.internal.core.CreateTypeHierarchyOperation.executeOperation(CreateTypeHierarchyOperation.java:90)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:728)
	at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:788)
	at org.eclipse.jdt.internal.core.JavaProject.newTypeHierarchy(JavaProject.java:2412)
	at org.eclipse.jdt.internal.core.JavaProject.newTypeHierarchy(JavaProject.java:2390)
Comment 14 Satyam Kandula CLA 2012-01-01 23:33:25 EST
(In reply to comment #12 and comment #13)
Mauro and Nicolas,
Is there a way you can give a reproducible testcase?
Comment 15 Mauro Molinari CLA 2012-01-03 07:04:46 EST
(In reply to comment #14)
> (In reply to comment #12 and comment #13)
> Mauro and Nicolas,
> Is there a way you can give a reproducible testcase?

Hi Satyam,
unfortunately, as I said, when I got that exception I was working on a huge project with proprietary code. Moreover, I can't reproduce deterministically :-(
Comment 16 Satyam Kandula CLA 2012-01-24 08:19:00 EST
*** Bug 369511 has been marked as a duplicate of this bug. ***
Comment 17 Satyam Kandula CLA 2012-02-01 01:14:37 EST
Created attachment 210353 [details]
Proposed patch

An unresolved type in some class files seems to cause an AbortCompilation exception which in turn is not initializing some fields. We shouldn't be worrying about this especially during search and more in the class files. This patch makes use of the new filed introduced as part of fix for bug 360164 which will not throw up AbortCompilation when an unresolved type is run into.
Comment 18 Satyam Kandula CLA 2012-02-01 01:19:51 EST
Released the patch through commit c543e3e3882451fde43cbe4b896f41a0fa7dc69f
Comment 19 Mauro Molinari CLA 2012-02-01 01:49:06 EST
Hi Satyam,
what's the target milestone for this?
Comment 20 Satyam Kandula CLA 2012-02-01 03:45:54 EST
Thanks for reminding. This is in 3.8M6. Please try out today's nightly build.
Comment 21 Satyam Kandula CLA 2012-02-03 05:21:34 EST
Peter, Mauro and Nicolas, 
Can you please try out in the lastest nightly build and let me know if this fixes your problem.
Comment 22 Nicolas Cabanis CLA 2012-02-07 06:07:02 EST
Unfortunately, this does not solve my problem. It's still the same stack.

I found out, it is only a single class file, that is problematic. It doesn't look any special. It's the AustrittAssistant$1.class of the attachted zip file. Unfortunately, it seems not to be reproducable with the small example - only with the other classes.
Comment 23 Nicolas Cabanis CLA 2012-02-07 06:07:41 EST
Created attachment 210634 [details]
Class files leading to the NPE
Comment 24 Satyam Kandula CLA 2012-02-07 09:31:43 EST
(In reply to comment #23)
> Created attachment 210634 [details]
> Class files leading to the NPE
Thanks for trying out and given the class files. I missed seeing the call stack properly. The problem I have tackled is (probably) similar but it is from a different call stack. I will see if I can extend the same fix or if I can handle it in a different manner. 
Reopening to fix this.
Comment 25 Satyam Kandula CLA 2012-02-29 07:56:53 EST
I extended the fix to take care of 'missing types' even during hierarchy api. This looks the better way. Released through the commit c886d02294a141648a4834ce44dd29510bcd61cd.
Comment 26 Jay Arthanareeswaran CLA 2012-03-13 03:55:11 EDT
Verified for 3.8 M6 by code inspection.