Bug 328554 - [move method] NPE during move method refactoring
Summary: [move method] NPE during move method refactoring
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 3.7 M4   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-24 16:47 EDT by Glenview Jeff CLA
Modified: 2010-11-29 13:21 EST (History)
1 user (show)

See Also:


Attachments
Gzipped log file as requested (14.81 KB, application/x-gzip)
2010-10-25 09:54 EDT, Glenview Jeff CLA
no flags Details
Proposed fix (15.54 KB, patch)
2010-10-26 20:26 EDT, Olivier Thomann CLA
no flags Details | Diff
Proposed fix (1.07 KB, patch)
2010-10-29 11:41 EDT, Olivier Thomann CLA
no flags Details | Diff
fix and test (4.66 KB, patch)
2010-11-29 13:21 EST, Markus Keller CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Glenview Jeff CLA 2010-10-24 16:47:20 EDT
Build Identifier: M20090917-0800

Manually (not using refactor assist) move a field F in class A to class B and this field is used by a method in class A.  The method will show an error because it doesn't know .

Then try to use refactor move method from class A to class B.  You'll receive the error "an unhandled exception occurred while performing the refactoring."

Reproducible: Always

Steps to Reproduce:
Manually (not using refactor assist) move a field F in class A to class B and this field is used by a method in class A.  The method will show an error because it doesn't know .

Then try to use refactor move method from class A to class B.  You'll receive the error "an unhandled exception occurred while performing the refactoring."
Comment 1 Olivier Thomann CLA 2010-10-24 20:23:09 EDT
Would it be possible to get the .log file inside the .metadata folder?
Comment 2 Glenview Jeff CLA 2010-10-25 09:54:44 EDT
Created attachment 181635 [details]
Gzipped log file as requested
Comment 3 Olivier Thomann CLA 2010-10-25 10:02:26 EDT
Ok, this seems to be the problem that you are getting:java.lang.NullPointerException
	at org.eclipse.jdt.internal.corext.dom.Bindings.equals(Bindings.java:78)
	at org.eclipse.jdt.internal.corext.refactoring.structure.MoveInstanceMethodProcessor$MethodBodyRewriter.visit(MoveInstanceMethodProcessor.java:632)
	at org.eclipse.jdt.core.dom.SimpleName.accept0(SimpleName.java:148)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2480)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2528)
	at org.eclipse.jdt.core.dom.ReturnStatement.accept0(ReturnStatement.java:136)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2480)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2551)
	at org.eclipse.jdt.core.dom.Block.accept0(Block.java:136)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2480)
	at org.eclipse.jdt.internal.corext.refactoring.structure.MoveInstanceMethodProcessor.createMethodBody(MoveInstanceMethodProcessor.java:2055)
	at org.eclipse.jdt.internal.corext.refactoring.structure.MoveInstanceMethodProcessor.createMethodCopy(MoveInstanceMethodProcessor.java:2224)
	at org.eclipse.jdt.internal.corext.refactoring.structure.MoveInstanceMethodProcessor.createChangeManager(MoveInstanceMethodProcessor.java:1776)
	at org.eclipse.jdt.internal.corext.refactoring.structure.MoveInstanceMethodProcessor.checkFinalConditions(MoveInstanceMethodProcessor.java:1270)
	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:211)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1800)
	at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)

Would it be possible for you to provide a self-containing test that reproduces this issue ?
You are getting a null binding and we need to understand why.
Thanks.
Comment 4 Glenview Jeff CLA 2010-10-25 15:56:08 EDT
Did you attempt to follow my instructions to reproduce?  I noticed that I couldn't reproduce it on Helios, so please make sure to use last year's version.

Thanks,
Jeff
Comment 5 Olivier Thomann CLA 2010-10-26 10:52:16 EDT
(In reply to comment #0)
> Steps to Reproduce:
> Manually (not using refactor assist) move a field F in class A to class B and
> this field is used by a method in class A.  The method will show an error
> because it doesn't know .
> 
> Then try to use refactor move method from class A to class B.  You'll receive
> the error "an unhandled exception occurred while performing the refactoring."
Do you mean that you are using refactoring on the code that contains the error reported in the first step ?
Comment 6 Glenview Jeff CLA 2010-10-26 12:21:39 EDT
(In reply to comment #5)
> (In reply to comment #0)
> > Steps to Reproduce:
> > Manually (not using refactor assist) move a field F in class A to class B and
> > this field is used by a method in class A.  The method will show an error
> > because it doesn't know .
> > 
> > Then try to use refactor move method from class A to class B.  You'll receive
> > the error "an unhandled exception occurred while performing the refactoring."
> Do you mean that you are using refactoring on the code that contains the error
> reported in the first step ?

Yes.
Comment 7 Olivier Thomann CLA 2010-10-26 17:17:58 EDT
(In reply to comment #4)
> Did you attempt to follow my instructions to reproduce?  I noticed that I
> couldn't reproduce it on Helios, so please make sure to use last year's
> version.
There is no more updates of the 3.5.x stream. Could you please try your test case with 3.6.1?
Thanks.
Comment 8 Olivier Thomann CLA 2010-10-26 20:22:25 EDT
I got this error:

java.lang.NullPointerException
at org.eclipse.jdt.internal.core.search.matching.FieldLocator.reportDeclaration(FieldLocator.java:281)
at org.eclipse.jdt.internal.core.search.matching.FieldLocator.matchReportReference(FieldLocator.java:153)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2219)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2694)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2421)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.process(MatchLocator.java:1673)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1083)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1124)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1256)
at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:94)
at org.eclipse.jdt.internal.core.search.BasicSearchEngine.searchDeclarations(BasicSearchEngine.java:1513)
at org.eclipse.jdt.internal.core.search.BasicSearchEngine.searchDeclarationsOfAccessedFields(BasicSearchEngine.java:1561)
at org.eclipse.jdt.core.search.SearchEngine.searchDeclarationsOfAccessedFields(SearchEngine.java:1120)
at org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine2.searchReferencedFields(RefactoringSearchEngine2.java:513)
at org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor.adjustVisibility(MemberVisibilityAdjustor.java:739)
at org.eclipse.jdt.internal.corext.refactoring.structure.MoveInstanceMethodProcessor.createChangeManager(MoveInstanceMethodProcessor.java:1778)
at org.eclipse.jdt.internal.corext.refactoring.structure.MoveInstanceMethodProcessor.checkFinalConditions(MoveInstanceMethodProcessor.java:1274)
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:1975)
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)

This is also reproducable in 3.6.1 and HEAD.
I could not reproduce your initial issue.

So you either better describe your steps or you try with 3.6.1 to tell me if you also get it with this build.
Comment 9 Olivier Thomann CLA 2010-10-26 20:26:01 EDT
Created attachment 181792 [details]
Proposed fix

Patch for the second exception since I cannot reproduce the first one.
Comment 10 Glenview Jeff CLA 2010-10-27 09:10:53 EDT
Oliver:

Thanks so much for looking into this.  It's not clear to me what you're doing or asking for.  You've begun to talk about two different exceptions and mentioned that you've been able to reproduce one of them.  I was only reporting one particular bug.  

I believe I described how to reproduce it.  I had asked if you were able to reproduce it using the steps I described with the version of Eclipse I reported.  Have you been able to do this?

Thanks,
Jeff

(In reply to comment #9)
> Created an attachment (id=181792) [details]
> Proposed fix
> 
> Patch for the second exception since I cannot reproduce the first one.
Comment 11 Olivier Thomann CLA 2010-10-27 09:17:16 EDT
(In reply to comment #10)
> I believe I described how to reproduce it.  I had asked if you were able to
> reproduce it using the steps I described with the version of Eclipse I
> reported.  Have you been able to do this?
No, this is too general. Trying to reproduce it I caused another exception which is fixed now.

This is your steps:
<< Manually (not using refactor assist) move a field F in class A to class B and
this field is used by a method in class A.  The method will show an error
because it doesn't know .

Then try to use refactor move method from class A to class B.  You'll receive
the error "an unhandled exception occurred while performing the refactoring." >>

It would be easier if you actually describe what you have in A, B,..

So something like this:
1) Create a new Java project
2) Create a class A in this project with the following contents:
....

3) Create a class B in this project with the following contents:
....

4) Go to A and delete the field F.
5) You should see an error ..... at this moment reported again the method .... in A.
6) Select .... and use the Move refactoring to the class B.
7) You should get the exception in the log.

Something like this would let me reproduce this issue more clearly. Hope you can provide such steps for further investigations.
Targetting M4 if I get steps to reproduce this issue.
Comment 12 Olivier Thomann CLA 2010-10-27 09:18:01 EDT
(In reply to comment #11)
> Targetting M4 if I get steps to reproduce this issue.
or 3.6.2 is the problem can be reproduced in 3.6.x since you are getting it inside 3.5.x which doesn't have any further updates.
Comment 13 Olivier Thomann CLA 2010-10-29 11:24:47 EDT
Reproduced.
Investigating.
Comment 14 Olivier Thomann CLA 2010-10-29 11:34:57 EDT
Steps to reproduce:
1) Create a class A with the following contents:
package p;

public class A {
	void foo(B b) {
		int j = i;
		System.out.println(j);
	}
}

2) Create a class B with the following contents:
package p;

public class B {
}
3) Invoke move refactoring on the method foo
4) The exception will be thrown.

There is a missing null check as the binding for 'i' is null.

If you replace foo with:
	void foo(B b) {
		int j = this.i;
		System.out.println(j);
	}
then you would get the exception I got in bug 328786.
Comment 15 Olivier Thomann CLA 2010-10-29 11:41:53 EDT
Created attachment 182058 [details]
Proposed fix

Regression test needs to be added.
Comment 16 Olivier Thomann CLA 2010-10-29 11:48:14 EDT
Moving to JDT/UI
Comment 17 Markus Keller CLA 2010-11-29 13:21:13 EST
Created attachment 184064 [details]
fix and test

Fixes a few more similar cases where missing bindings caused trouble.
Comment 18 Markus Keller CLA 2010-11-29 13:21:51 EST
Fixed in HEAD.