Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 411608 - [1.8][extract method] NPE while invoking extract method on a variable in interface default or static method
Summary: [1.8][extract method] NPE while invoking extract method on a variable in inte...
Status: CLOSED DUPLICATE of bug 406786
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.3   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-25 10:39 EDT by Martin Mathew CLA
Modified: 2013-06-25 13:28 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Mathew CLA 2013-06-25 10:39:20 EDT
Consider the below interface:
package pack3;

public interface Bug1 {

	public static void statictM1(String s) {
		System.out.println(s);//Select 's' and press Ctrl+1
	}
}
Invoke Quick Assist on 's' and select 'Extract Method', NPE is thrown. The problem is in ExtractMethodAnalyzer#checkInput(..) where type.getSuperclass() is invoked, the Javadoc for #getSuperclass() clearly states that it will return null if the typebinding is an interface.

Below is the stacktrace: 
	at org.eclipse.jdt.internal.corext.dom.Bindings.findMethodInType(Bindings.java:358)
	at org.eclipse.jdt.internal.corext.dom.Bindings.findMethodInHierarchy(Bindings.java:385)
	at org.eclipse.jdt.internal.corext.refactoring.Checks.checkMethodInHierarchy(Checks.java:338)
	at org.eclipse.jdt.internal.corext.refactoring.code.ExtractMethodAnalyzer.checkInput(ExtractMethodAnalyzer.java:321)
	at org.eclipse.jdt.internal.corext.refactoring.code.ExtractMethodRefactoring.checkFinalConditions(ExtractMethodRefactoring.java:474)

The other concerns regarding this bug is
1. Should we allow 'Extract Method' on an interface.
2. If allowed what should be the the signature of the extracted method. No doubt, it has to be public. If the method is extracted from a default interface method, then we keep the extracted method as 'default' and if extracted from a static method then let the extracted method be 'static'.

Markus, kindly share your thoughts.
Comment 1 Noopur Gupta CLA 2013-06-25 13:28:22 EDT

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