Bug 13063 - NPE in extract method
Summary: NPE in extract method
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows NT
: P1 major (vote)
Target Milestone: 2.0 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-04-09 08:16 EDT by Dani Megert CLA
Modified: 2002-04-10 15:06 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2002-04-09 08:16:08 EDT
1. Added new code to JavaBrowsingPerspectiveFactory
2. Selected some of that code (no save)
3. Extract method

java.lang.NullPointerException
	at
org.eclipse.jdt.core.dom.DefaultBindingResolver.returnBindingForQualifiedNamePart(DefaultBindingResolver.java:618)
	at
org.eclipse.jdt.core.dom.DefaultBindingResolver.internalResolveNameForSimpleName(DefaultBindingResolver.java:660)
	at
org.eclipse.jdt.core.dom.DefaultBindingResolver.resolveName(DefaultBindingResolver.java:146)
	at org.eclipse.jdt.core.dom.Name.resolveBinding(Name.java:75)
	at
org.eclipse.jdt.internal.corext.refactoring.code.LocalTypeAnalyzer.visit(LocalTypeAnalyzer.java:45)
	at org.eclipse.jdt.core.dom.SimpleName.accept0(SimpleName.java:88)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:957)
	at org.eclipse.jdt.core.dom.QualifiedName.accept0(QualifiedName.java:81)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:986)
	at org.eclipse.jdt.core.dom.MethodInvocation.accept0(MethodInvocation.java:87)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:957)
	at org.eclipse.jdt.core.dom.ExpressionStatement.accept0(ExpressionStatement.java:73)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:986)
	at org.eclipse.jdt.core.dom.Block.accept0(Block.java:73)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:957)
	at org.eclipse.jdt.core.dom.IfStatement.accept0(IfStatement.java:93)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:986)
	at org.eclipse.jdt.core.dom.Block.accept0(Block.java:73)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:957)
	at org.eclipse.jdt.core.dom.MethodDeclaration.accept0(MethodDeclaration.java:173)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:906)
	at
org.eclipse.jdt.internal.corext.refactoring.code.LocalTypeAnalyzer.perform(LocalTypeAnalyzer.java:34)
	at
org.eclipse.jdt.internal.corext.refactoring.code.ExtractMethodAnalyzer.endVisit(ExtractMethodAnalyzer.java:418)
	at org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:140)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:906)
	at
org.eclipse.jdt.internal.corext.refactoring.code.ExtractMethodRefactoring.checkActivation(ExtractMethodRefactoring.java:166)
	at
org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter.activate(RefactoringStarter.java:74)
	at
org.eclipse.jdt.internal.ui.refactoring.actions.TextSelectionBasedRefactoringAction.run(TextSelectionBasedRefactoringAction.java:28)
	at
org.eclipse.jdt.internal.ui.refactoring.actions.TextSelectionAction.run(TextSelectionAction.java:80)
	at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:204)
	at
org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:407)
	at
org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent(ActionContributionItem.java(Compiled
Code))
	at
org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent(ActionContributionItem.java(Compiled
Code))
	at
org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent(ActionContributionItem.java(Compiled
Code))
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java(Compiled Code))
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java(Compiled Code))
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java(Compiled Code))
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java(Compiled Code))
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java(Compiled Code))
	at org.eclipse.ui.internal.Workbench.run(Workbench.java:738)
	at org.eclipse.core.internal.boot.InternalBootLoader.run(InternalBootLoader.java:777)
	at org.eclipse.core.boot.BootLoader.run(BootLoader.java:319)
	at java.lang.reflect.Method.invoke(Native Method)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:190)
	at org.eclipse.core.launcher.Main.run(Main.java:549)
	at org.eclipse.core.launcher.UIMain.main(UIMain.java:52)
Comment 1 Dirk Baeumer CLA 2002-04-09 10:24:42 EDT
This is a AST problem. Moving to JCore
Comment 2 Olivier Thomann CLA 2002-04-09 10:28:05 EDT
I would need a test case. Without this, it can be really long to fix the bug.
Could you please provide the code you selected to "extract method"?
Comment 3 Olivier Thomann CLA 2002-04-10 11:10:21 EDT
Please provide a test case if you want this PR to be fixed.
Comment 4 Dani Megert CLA 2002-04-10 11:21:53 EDT
no problem here it is:

1. Self-hosting workspace
2. Open JavaBrowsingPerspectiveFactory.java (revision 1.3)
3. Under the method declaration of "createInitialLayout" add:
		if (fgJavaElementFromAction == null)
			return true;
		int type= fgJavaElementFromAction.getElementType();
		return type == IJavaElement.JAVA_MODEL || type == IJavaElement.JAVA_PROJECT ||
type == IJavaElement.PACKAGE_FRAGMENT_ROOT;
4. Select the code which you just added
5. Refactor -> Extract Method

Comment 5 Olivier Thomann CLA 2002-04-10 12:33:43 EDT
And this revision corresponds to which build?
JavaBrowsingPerspectiveFactory.java 
(revision 1.3)
Comment 6 Dani Megert CLA 2002-04-10 12:40:35 EDT
Build where the problem appears: 20020409

The revision of the file is not part of a build (no tag). Simply use the current
build (20020409) and get the correct revision from dev.eclipse.org
Comment 7 Olivier Thomann CLA 2002-04-10 12:44:44 EDT
I tried to reproduce this problem without success. Could you please tell me  exactly where in the 
source of JavaBrowsingPerspectiveFactory you add the code. The method createInitialLayout 
returns void. So adding code that returns a boolean is invalid. I tried but I could not reproduce.
Comment 8 Olivier Thomann CLA 2002-04-10 14:42:07 EDT
Reproduced with latest code sent by email. I am working on it.
Comment 9 Olivier Thomann CLA 2002-04-10 14:57:19 EDT
The problem comes from the fact that IJavaElement.JAVA_MODEL cannot be resolved properly, 
because IJavaElement cannot be resolved. So in this case when trying to resolve the name 
"IJavaElement" or "JAVA_MODEL", I expect null to be returned instead of a NPE.
In this case the 
extracted method doesn't return the proper type. This might be a bug in this code. It returns void 
instead of boolean.
I will fix the name resolution code to return null instead of failing with a 
NPE. I am expecting you to fix the other part (return type is void instead of boolean).
Comment 10 Olivier Thomann CLA 2002-04-10 15:05:41 EDT
Another bug is to generate after the extract method a return statement like:
return test(); if 
"test" is the name of the extracted method where the return type of the method is void. This is 
invalid and I would expect the extraction of the method to fail instead of generating invalid 
code.
The initial problem is fixed and released in HEAD.