Community
Participate
Working Groups
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.
Provide us the complete code snippet without any compilation errors to reproduce the issue.
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'.
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)
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.