Bug 429416 - [move method] IAE when moving method from anonymous class
Summary: [move method] IAE when moving method from anonymous class
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.3.1   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-02 14:56 EST by Erlend Kristiansen CLA
Modified: 2020-03-14 01:49 EDT (History)
3 users (show)

See Also:


Attachments
Project with code to reproduce error (872 bytes, application/x-gzip)
2014-03-03 02:57 EST, Erlend Kristiansen CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Erlend Kristiansen CLA 2014-03-02 14:56:22 EST
In the following code, 'TakingB' is an interface, while 'B' and 'C' are regular classes:

TakingB anonymous = new TakingB() {
    @Override
    public void foo(B b) {
        bar(b.c);
    }

    private void bar(C c) {
        c.a.foo();
	c.a.bar();
    }
};

When trying to move the method 'bar' from the anonymous class above to the class 'C', an internal error occurs. It is caused by an IllegalArgumentException thrown in org.eclipse.jdt.core.dom.SimpleName.setIdentifier(String) line: 194.

The problem seems to stem from the org.eclipse.jdt.internal.corext.refactoring.structure.MoveInstanceMethodProcessor. The third entry from the top of the stack trace from the debug perspective reads:

MoveInstanceMethodProcessor.createInlinedMethodInvocation(CompilationUnitRewrite, MethodDeclaration, SearchMatch, Map<IMember,IncomingMemberVisibilityAdjustment>, boolean, RefactoringStatus) line: 1934

It is the last line of:

final ITypeBinding declaring= method.getDeclaringClass();
if (declaring != null)
    expression.setQualifier(rewrite.getAST().newSimpleName(declaring.getName()));

Eclipse seems to try to qualify a 'this' expression with the name of the declaring class, but since the declaring class of the method is anonymous, 'declaring.getName()' returns an empty string, which in turn causes an IllegalArgumentException in SimpleName.
Comment 1 Martin Mathew CLA 2014-03-02 23:00:20 EST
Provide us the complete code snippet without any compilation errors to reproduce the issue.
Comment 2 Erlend Kristiansen CLA 2014-03-03 02:57:38 EST
Created attachment 240441 [details]
Project with code to reproduce error

The anonymous class is found in the main method. Try to move its 'bar' method to the class 'C'.
Comment 3 Martin Mathew CLA 2014-03-03 04:11:01 EST
Thanks for the code snippet. I am able to reproduce the issue. The exception thrown is:
 java.lang.IllegalArgumentException: Invalid identifier : ><
	at org.eclipse.jdt.core.dom.SimpleName.setIdentifier(SimpleName.java:195)
	at org.eclipse.jdt.core.dom.AST.newSimpleName(AST.java:2206)
	at org.eclipse.jdt.internal.corext.refactoring.structure.MoveInstanceMethodProcessor.createInlinedMethodInvocation(MoveInstanceMethodProcessor.java:1939)
	at org.eclipse.jdt.internal.corext.refactoring.structure.MoveInstanceMethodProcessor.createMethodDelegator(MoveInstanceMethodProcessor.java:2418)
	at org.eclipse.jdt.internal.corext.refactoring.structure.MoveInstanceMethodProcessor.createChangeManager(MoveInstanceMethodProcessor.java:1824)
	at org.eclipse.jdt.internal.corext.refactoring.structure.MoveInstanceMethodProcessor.checkFinalConditions(MoveInstanceMethodProcessor.java:1308)
	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:2333)
	at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:122)
Comment 4 Eclipse Genie CLA 2020-03-14 01:49:24 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.