Bug 181380 - [search] NPE in FieldLocator.matchReportReference
Summary: [search] NPE in FieldLocator.matchReportReference
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2.2   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 3.3 M6   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords: needinfo
Depends on: 66177
Blocks:
  Show dependency tree
 
Reported: 2007-04-06 02:55 EDT by maarten meijer CLA
Modified: 2007-04-20 09:23 EDT (History)
0 users

See Also:


Attachments
mylar/context/zip (2.99 KB, application/octet-stream)
2007-04-16 18:07 EDT, maarten meijer CLA
no flags Details
Log with search options on (12.35 KB, text/plain)
2007-04-17 04:37 EDT, maarten meijer CLA
no flags Details
.options file to activate Search trace (159 bytes, text/plain)
2007-04-17 07:01 EDT, Frederic Fusier CLA
no flags Details
Search trace before error occurs (23.86 KB, text/plain)
2007-04-17 15:20 EDT, maarten meijer CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description maarten meijer CLA 2007-04-06 02:55:35 EDT
I tried to do a Rename Variable refactoring on a public field, when this error occurs everytime.

-- Error Log --
Date: Fri Apr 06 08:49:57 CEST 2007
Message: Internal Error
Severity: Error
Plugin ID: org.eclipse.ltk.ui.refactoring
Stack Trace:
java.lang.reflect.InvocationTargetException
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:350)
	at org.eclipse.ltk.internal.ui.refactoring.RefactoringWizardDialog2.run(RefactoringWizardDialog2.java:304)
	at org.eclipse.ltk.ui.refactoring.RefactoringWizard.createChange(RefactoringWizard.java:571)
	at org.eclipse.ltk.ui.refactoring.RefactoringWizard.computeUserInputSuccessorPage(RefactoringWizard.java:414)
	at org.eclipse.ltk.ui.refactoring.UserInputWizardPage.computeSuccessorPage(UserInputWizardPage.java:75)
	at org.eclipse.ltk.ui.refactoring.UserInputWizardPage.getNextPage(UserInputWizardPage.java:115)
	at org.eclipse.ltk.internal.ui.refactoring.RefactoringWizardDialog2.nextOrPreviewPressed(RefactoringWizardDialog2.java:475)
	at org.eclipse.ltk.internal.ui.refactoring.RefactoringWizardDialog2.access$0(RefactoringWizardDialog2.java:472)
	at org.eclipse.ltk.internal.ui.refactoring.RefactoringWizardDialog2$1.widgetSelected(RefactoringWizardDialog2.java:660)
	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:1496)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1520)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1505)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1279)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3312)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2941)
	at org.eclipse.jface.window.Window.runEventLoop(Window.java:820)
	at org.eclipse.jface.window.Window.open(Window.java:796)
	at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation$1.run(RefactoringWizardOpenOperation.java:132)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
	at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation.run(RefactoringWizardOpenOperation.java:145)
	at org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter.activate(RefactoringStarter.java:40)
	at org.eclipse.jdt.internal.ui.refactoring.UserInterfaceStarter.activate(UserInterfaceStarter.java:56)
	at org.eclipse.jdt.internal.ui.refactoring.reorg.RenameUserInterfaceStarter.activate(RenameUserInterfaceStarter.java:155)
	at org.eclipse.jdt.ui.refactoring.RenameSupport.openDialog(RenameSupport.java:114)
	at org.eclipse.jdt.internal.corext.refactoring.RefactoringExecutionStarter.startRenameRefactoring(RefactoringExecutionStarter.java:382)
	at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.run(RenameJavaElementAction.java:172)
	at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.run(RenameJavaElementAction.java:131)
	at org.eclipse.jdt.ui.actions.RenameAction.run(RenameAction.java:117)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:271)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:243)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:499)
	at org.eclipse.ui.commands.ActionHandler.execute(ActionHandler.java:185)
	at org.eclipse.ui.internal.handlers.LegacyHandlerWrapper.execute(LegacyHandlerWrapper.java:109)
	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:461)
	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:424)
	at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:160)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyboard.java:466)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:799)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:846)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:564)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.java:506)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(WorkbenchKeyboard.java:122)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1109)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1495)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1520)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1505)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1557)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1552)
	at org.eclipse.swt.widgets.Control.kEventUnicodeKeyPressed(Control.java:1820)
	at org.eclipse.swt.widgets.Composite.kEventUnicodeKeyPressed(Composite.java:583)
	at org.eclipse.swt.widgets.Control.kEventTextInputUnicodeForKeyEvent(Control.java:1812)
	at org.eclipse.swt.widgets.Widget.textInputProc(Widget.java:2000)
	at org.eclipse.swt.widgets.Display.textInputProc(Display.java:3838)
	at org.eclipse.swt.internal.carbon.OS.SendEventToEventTarget(Native Method)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2910)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1930)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1894)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:422)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:95)
	at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)
	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:400)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
	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:585)
	at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
	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.internal.core.search.matching.FieldLocator.matchReportReference(FieldLocator.java:221)
	at org.eclipse.jdt.internal.core.search.matching.PatternLocator.matchReportReference(PatternLocator.java:398)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2034)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2440)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2187)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.process(MatchLocator.java:1548)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1033)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1074)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1180)
	at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:94)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:212)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:490)
	at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:538)
	at org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine.internalSearch(RefactoringSearchEngine.java:145)
	at org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine.search(RefactoringSearchEngine.java:131)
	at org.eclipse.jdt.internal.corext.refactoring.rename.RenameFieldProcessor.getNewReferences(RenameFieldProcessor.java:837)
	at org.eclipse.jdt.internal.corext.refactoring.rename.RenameFieldProcessor.analyzeRenameChanges(RenameFieldProcessor.java:799)
	at org.eclipse.jdt.internal.corext.refactoring.rename.RenameFieldProcessor.createChanges(RenameFieldProcessor.java:626)
	at org.eclipse.jdt.internal.corext.refactoring.rename.RenameFieldProcessor.doCheckFinalConditions(RenameFieldProcessor.java:441)
	at org.eclipse.jdt.internal.corext.refactoring.rename.JavaRenameProcessor.checkFinalConditions(JavaRenameProcessor.java:46)
	at org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring.checkFinalConditions(ProcessorBasedRefactoring.java:175)
	at org.eclipse.ltk.core.refactoring.CheckConditionsOperation.run(CheckConditionsOperation.java:83)
	at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:118)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1737)
	at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:113)
Comment 1 Frederic Fusier CLA 2007-04-14 10:32:13 EDT
Can you provide a simple test case to help us to reproduce the problem?
Thanks
Comment 2 maarten meijer CLA 2007-04-15 04:04:30 EDT
(In reply to comment #1)
> Can you provide a simple test case to help us to reproduce the problem?
Will try do in the next week. 

I'm in a large scale refactoring where I first did a facade with get/setNewName methods in a subclass, and then later decided to rename the protected or public fields as well.
It apparenrtly matches the get/settter in the facde or something.
Maybe the testcase will not be so simple ;-)

I think the key is in:
Caused by: java.lang.NullPointerException
        at
org.eclipse.jdt.internal.core.search.matching.FieldLocator.matchReportReference(FieldLocator.java:221)

I'm using version 3.2.2 by the way...
Comment 3 Frederic Fusier CLA 2007-04-16 11:50:57 EDT
(In reply to comment #2)
> Will try do in the next week. 
> 
OK, thanks

> I'm in a large scale refactoring where I first did a facade with get/setNewName
> methods in a subclass, and then later decided to rename the protected or public
> fields as well.
> It apparenrtly matches the get/settter in the facde or something.
> Maybe the testcase will not be so simple ;-)
> 
I guess if it was simple, then it would occur before... If this NPE is always reproducible, you can also activate Search debug trace by changing following lines in .options file:

# Turn on debug tracing for org.eclipse.jdt.core plugin
org.eclipse.jdt.core/debug=true

# Reports java search activity
org.eclipse.jdt.core/debug/search=true

Then copy the console outputs in a file and attach it to this bug...

> I think the key is in:
> Caused by: java.lang.NullPointerException
>         at
> org.eclipse.jdt.internal.core.search.matching.FieldLocator.matchReportReference(FieldLocator.java:221)
> 
Of course, this line is already under the spot lights! But we'd rather prefer to understand why an object was unexpectedly null instead of putting a null check to avoid the exception...

> I'm using version 3.2.2 by the way...
> 
Thanks for the precision.
Comment 4 maarten meijer CLA 2007-04-16 18:07:41 EDT
I think I know what is happening, and the problem is related to my workaround for bug#66177 no PDE build from linked resource. I have a non-PDE basic library where I develop in. To include in PDE projects I use an ANT copy of relevant packages to a PDE library project for use by the plugins I'm developing. This gives the following tree:
+ SomeLibrary (for PDE)
+ src
=   SomeClass.java
* ant-duplicate.xml (for copy builder)
+ SomeLibrary (basic)
+ src
=   SomeClass.java

The problem occurs when trying to Rename some public or protected field in SomeLibrary (basic)/src/SomeClass.java

I suspect that the fatal NullPointer is returned when the search encounters an identically named field in an identically named class. The proper behavious in my view would be to show a dialog or just show them with a warning in Preview dialog. I will create the traces and add them as attachments.
Comment 5 maarten meijer CLA 2007-04-16 18:07:55 EDT
Created attachment 63958 [details]
mylar/context/zip
Comment 6 maarten meijer CLA 2007-04-16 18:27:59 EDT
I found plugin org.eclipse.jdt.core_3.2.3.v_686_R32x.jar
I unjarred it and changed the options as you described
==
# Turn on debug tracing for org.eclipse.jdt.core plugin ALREADY ON!
org.eclipse.jdt.core/debug=true

# Reports java search activity
org.eclipse.jdt.core/debug/search=true
==
I can repeat the error but where do I find the console output to send?
Comment 7 maarten meijer CLA 2007-04-17 04:37:45 EDT
Created attachment 64005 [details]
Log with search options on

debug.options contains:
# Turn on debug tracing for org.eclipse.jdt.core plugin
org.eclipse.jdt.core/debug=true

# Reports java search activity
org.eclipse.jdt.core/debug/search=true
Comment 8 Frederic Fusier CLA 2007-04-17 06:58:01 EDT
(In reply to comment #6)
> I found plugin org.eclipse.jdt.core_3.2.3.v_686_R32x.jar
> I unjarred it and changed the options as you described
> ==
> # Turn on debug tracing for org.eclipse.jdt.core plugin ALREADY ON!
> org.eclipse.jdt.core/debug=true
> 
> # Reports java search activity
> org.eclipse.jdt.core/debug/search=true
> ==
> I can repeat the error but where do I find the console output to send?
> 

Sorry I should give you more precise steps to activate the trace...

There's no need to unjar this jdt-core plugin jar file, you only need to have the .options file in the <eclipse install dir>/eclipse subdir and launch eclipse in a terminal window using following command line:
./eclipse -consoleLog -refresh -debug -showLocation -data <your workspace path> -vm <your VM path>

On my Linux box, using this command line, I got the Search trace in the terminal window from where I launched eclipse:
Thread[Worker-2,5,main] BasicSearchEngine.searchAllTypeNames(char[], char[], int, int, IJavaSearchScope, IRestrictedAccessTypeRequestor, int, IProgressMonitor)
Thread[Worker-2,5,main]         - package name: null
Thread[Worker-2,5,main]         - match rule: R_EXACT_MATCH
Thread[Worker-2,5,main]         - type name: !@$#!@
Thread[Worker-2,5,main]         - match rule: R_PATTERN_MATCH | R_CASE_SENSITIVE
Thread[Worker-2,5,main]         - search for: 5
Thread[Worker-2,5,main]         - scope: JavaWorkspaceScope

I guess it should be similar for a Mac/OS box...
Comment 9 Frederic Fusier CLA 2007-04-17 07:01:02 EDT
Created attachment 64019 [details]
.options file to activate Search trace

Note that the trace is not ON by default even with:
# Turn on debug tracing for org.eclipse.jdt.core plugin
org.eclipse.jdt.core/debug=true

You need to put -debug parameter in your command line to really have this trace activated...
Comment 10 Frederic Fusier CLA 2007-04-17 07:47:22 EDT
(In reply to comment #4)
> I think I know what is happening, and the problem is related to my workaround
> for bug#66177 no PDE build from linked resource. I have a non-PDE basic library
> where I develop in. To include in PDE projects I use an ANT copy of relevant
> packages to a PDE library project for use by the plugins I'm developing. This
> gives the following tree:
> + SomeLibrary (for PDE)
> + src
> =   SomeClass.java
> * ant-duplicate.xml (for copy builder)
> + SomeLibrary (basic)
> + src
> =   SomeClass.java
> 
> The problem occurs when trying to Rename some public or protected field in
> SomeLibrary (basic)/src/SomeClass.java
> 
> I suspect that the fatal NullPointer is returned when the search encounters an
> identically named field in an identically named class. The proper behavious in
> my view would be to show a dialog or just show them with a warning in Preview
> dialog. I will create the traces and add them as attachments.
> 
Can you provide more information on your set-up?
1) Are 'SomeLibrary (PDE)' and 'SomeLibrary (basic)' Java or Plug-in projects?
2) Is there any dependencies between these 2 projects?
3) How does the ant-duplicate.xml work (copy from PDE to basic, reverse way, 
   merge, other...)?
Comment 11 maarten meijer CLA 2007-04-17 09:01:49 EDT
After reading http://help.eclipse.org/help32/topic/org.eclipse.platform.doc.user/tasks/running_eclipse.htm#macosx
I've modified my eclipse.ini so it reads the description in debug.options as follows:

-debug /Applications/eclipse3.2.1/debug.options
-consolelog
-vmargs
-Xdock:icon=../Resources/Eclipse.icns
-XstartOnFirstThread
-Xbootclasspath/p:../../../plugins/org.eclipse.jdt.debug_3.2.1.r321_v20060731/jdi.jar
-Xms256m
-Xmx512m
-XX:MaxPermSize=256m
-Dorg.eclipse.swt.internal.carbon.smallFonts
-Dorg.eclipse.swt.internal.carbon.noFocusRing

But I get no sign of search activity in the .log file, just the exception.

Re test setup, I'm gradually building up test setup as described until I find on that reliably generates the error.
Comment 12 Frederic Fusier CLA 2007-04-17 11:12:29 EDT
(In reply to comment #11)
The trace outputs are never put in the .log file but in the console. Following comment 8 instructions should display these outputs in the the terminal window
from where you launched eclipse. Isn't Mac/OS an Unix operating system? If so, these instructions should work...
Does your debug.options file contains the lines for Search trace?
Can you also provide answers for comment 10 questions?
Comment 13 maarten meijer CLA 2007-04-17 14:36:03 EDT
 (In reply to comment #12)
> (In reply to comment #11)
> The trace outputs are never put in the .log file but in the console. Following
> comment 8 instructions should display these outputs in the the terminal window
> from where you launched eclipse. Isn't Mac/OS an Unix operating system? If so,
> these instructions should work...
Yes Mac OSX is unix like :-( but different. I expected the output to appear in the console.log file after using -consolelog, but alas.
Outputs should appear as well when I'm just using java search, right?
> Does your debug.options file contains the lines for Search trace?
Yes it includes that (see comment 7) Also I use -debug on the command line...via eclipse.ini
> Can you also provide answers for comment 10 questions?
I'm graduallty building the ever more complex MINIMAL set of two projects that will recreate the problem. 
It has to do with project SomeLibrary (for PDE) having SomeLibrary (basic) set as a dependency on its build path. When I switch that off, the problem goes away but I want the dependency set for refactorings to propagate towards the clients of this copied library as well.
I do ghet problems/warnings so far but no failures and error log entries.
Comment 14 maarten meijer CLA 2007-04-17 15:20:05 EDT
Created attachment 64087 [details]
Search trace before error occurs

Attachment is the trace created by using the following shell commands on mac osx:
cd /Applications/eclipse3.2.1/
./eclipse -os macosx -ws carbon -debug /Applications/eclipse3.2.1/debug.options -consolelog -keyring /Users/maarten/.eclipse_keyring -consoleLog -showlocation -data /Users/maarten/workspace-181380 | bbedit
The console output is then piped to bbeedit for saving and editing.
So what's the next step?
Comment 15 maarten meijer CLA 2007-04-20 09:06:47 EDT
I have downloaded Eclipse 3.3M6 and installed all my usual plugins. 
I then created a new workspace where I took the two projects from CVS.

When I refactor in version 3.2.2 the error occurs.

When I do the same in vevrsion 3.3M6 I do get multiple warnings about shadowing
'Another name will shadow access to the renamed element'
But the refactoring is execured without problems.

It appears the problem has gone away as a side effect of something else.
Comment 16 Frederic Fusier CLA 2007-04-20 09:23:08 EDT
Thanks for the feedback. So, I close this bug as WORKSFORME.

Please note that it does not mean that I do not believe it happens in 3.2.2.
But as I cannot reproduce it locally, I have no chance to find the original bug and set this bug as a duplicate of it...