@SneakyThrows prevents some Eclipse refactorings #668

Closed
lombokissues opened this Issue Jul 14, 2015 · 7 comments

Projects

None yet

1 participant

@lombokissues
Collaborator

Migrated from Google Code (issue 633)

@lombokissues
Collaborator

👤 jorn86   🕗 Jan 30, 2014 at 09:39 UTC

What steps will reproduce the problem?

  1. Have a method annotated with @ SneakyThrows
  2. Inside the method, use the Eclipse refactoring Extract local variable

Also reproducible with @ Synchronized, I guess this is related to inserting code at the start and end of the method.
Error is reproducible with other refactorings that insert code into the method as well, not with refactorings that insert code outside it (such as Extract method).

What is the expected output? What do you see instead?
Eclipse throws an error dialog saying Internal error: No target edit provided, and shows the stacktrace below in the error log.

What version of the product are you using? On what operating system?
Eclipse 4.3, Lombok 0.12.0, Windows 7

Please provide any additional information below.

Stack trace from error log:
java.lang.reflect.InvocationTargetException
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:421)
at org.eclipse.ltk.internal.ui.refactoring.RefactoringWizardDialog2.run(RefactoringWizardDialog2.java:331)
at org.eclipse.ltk.ui.refactoring.RefactoringWizard.internalPerformFinish(RefactoringWizard.java:637)
at org.eclipse.ltk.ui.refactoring.UserInputWizardPage.performFinish(UserInputWizardPage.java:153)
at org.eclipse.ltk.ui.refactoring.RefactoringWizard.performFinish(RefactoringWizard.java:710)
at org.eclipse.ltk.internal.ui.refactoring.RefactoringWizardDialog2.okPressed(RefactoringWizardDialog2.java:455)
at org.eclipse.jface.dialogs.Dialog.buttonPressed(Dialog.java:476)
at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:628)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1057)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4170)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3759)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:826)
at org.eclipse.jface.window.Window.open(Window.java:802)
at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation$1.run(RefactoringWizardOpenOperation.java:187)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation.run(RefactoringWizardOpenOperation.java:202)
at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation.run(RefactoringWizardOpenOperation.java:122)
at org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter.activate(RefactoringStarter.java:38)
at org.eclipse.jdt.ui.actions.ExtractTempAction.run(ExtractTempAction.java:88)
at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:279)
at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:251)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:499)
at org.eclipse.jface.commands.ActionHandler.execute(ActionHandler.java:119)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:90)
at sun.reflect.GeneratedMethodAccessor88.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:243)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:224)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:167)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:499)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:213)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.executeCommand(KeyBindingDispatcher.java:285)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.press(KeyBindingDispatcher.java:504)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.processKeyEvent(KeyBindingDispatcher.java:555)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.filterKeySequenceBindings(KeyBindingDispatcher.java:376)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.access$0(KeyBindingDispatcher.java:322)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher$KeyDownFilter.handleEvent(KeyBindingDispatcher.java:84)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1262)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1056)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1081)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1066)
at org.eclipse.swt.widgets.Control.traverse(Control.java:4107)
at org.eclipse.swt.widgets.Control.translateMnemonic(Control.java:3949)
at org.eclipse.swt.widgets.Composite.translateMnemonic(Composite.java:1206)
at org.eclipse.swt.widgets.Control.translateMnemonic(Control.java:3967)
at org.eclipse.swt.widgets.Display.translateMnemonic(Display.java:4777)
at org.eclipse.swt.widgets.Display.filterMessage(Display.java:1276)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3755)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1113)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:997)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:138)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:610)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:567)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
at org.eclipse.equinox.launcher.Main.main(Main.java:1426)
Caused by: org.eclipse.text.edits.MalformedTreeException: No target edit provided.
at org.eclipse.text.edits.CopySourceEdit.performConsistencyCheck(CopySourceEdit.java:239)
at org.eclipse.text.edits.TextEdit.traverseConsistencyCheck(TextEdit.java:873)
at org.eclipse.text.edits.CopySourceEdit.traverseConsistencyCheck(CopySourceEdit.java:214)
at org.eclipse.text.edits.TextEdit.traverseConsistencyCheck(TextEdit.java:869)
at org.eclipse.text.edits.TextEdit.traverseConsistencyCheck(TextEdit.java:869)
at org.eclipse.text.edits.TextEdit.traverseConsistencyCheck(TextEdit.java:869)
at org.eclipse.text.edits.TextEditProcessor.checkIntegrityDo(TextEditProcessor.java:176)
at org.eclipse.text.edits.TextEdit.dispatchCheckIntegrity(TextEdit.java:743)
at org.eclipse.text.edits.TextEditProcessor.performEdits(TextEditProcessor.java:151)
at org.eclipse.ltk.core.refactoring.TextChange.getPreviewDocument(TextChange.java:534)
at org.eclipse.ltk.core.refactoring.TextChange.getPreviewDocument(TextChange.java:403)
at org.eclipse.ltk.core.refactoring.TextChange.getPreviewContent(TextChange.java:411)
at org.eclipse.jdt.internal.corext.refactoring.code.ExtractTempRefactoring.checkNewSource(ExtractTempRefactoring.java:559)
at org.eclipse.jdt.internal.corext.refactoring.code.ExtractTempRefactoring.checkFinalConditions(ExtractTempRefactoring.java:504)
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:2345)
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Root exception:
org.eclipse.text.edits.MalformedTreeException: No target edit provided.
at org.eclipse.text.edits.CopySourceEdit.performConsistencyCheck(CopySourceEdit.java:239)
at org.eclipse.text.edits.TextEdit.traverseConsistencyCheck(TextEdit.java:873)
at org.eclipse.text.edits.CopySourceEdit.traverseConsistencyCheck(CopySourceEdit.java:214)
at org.eclipse.text.edits.TextEdit.traverseConsistencyCheck(TextEdit.java:869)
at org.eclipse.text.edits.TextEdit.traverseConsistencyCheck(TextEdit.java:869)
at org.eclipse.text.edits.TextEdit.traverseConsistencyCheck(TextEdit.java:869)
at org.eclipse.text.edits.TextEditProcessor.checkIntegrityDo(TextEditProcessor.java:176)
at org.eclipse.text.edits.TextEdit.dispatchCheckIntegrity(TextEdit.java:743)
at org.eclipse.text.edits.TextEditProcessor.performEdits(TextEditProcessor.java:151)
at org.eclipse.ltk.core.refactoring.TextChange.getPreviewDocument(TextChange.java:534)
at org.eclipse.ltk.core.refactoring.TextChange.getPreviewDocument(TextChange.java:403)
at org.eclipse.ltk.core.refactoring.TextChange.getPreviewContent(TextChange.java:411)
at org.eclipse.jdt.internal.corext.refactoring.code.ExtractTempRefactoring.checkNewSource(ExtractTempRefactoring.java:559)
at org.eclipse.jdt.internal.corext.refactoring.code.ExtractTempRefactoring.checkFinalConditions(ExtractTempRefactoring.java:504)
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:2345)
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)

@lombokissues
Collaborator

👤 reinierz   🕗 Feb 07, 2014 at 02:19 UTC

I added a commit to master branch that adds a new build target called 'eclipseForDebugging'. It's like 'eclipse', except it adds the eclipse deps straight from your eclipse install instead of the default (fairly ancient) eclipse, and adds a couple of non-deps which are nevertheless useful (to set breakpoints and such).

It's step one to fixing this and a couple of other places where eclipse integration is less than perfect.

@lombokissues
Collaborator

👤 r.spilker   🕗 Feb 18, 2014 at 22:28 UTC

During debugging we noticed that ASTRewrite﹟internalRewriteAST gets passed a Block in normal cases and a LocalVariableDeclaration when it fails. It might make sense that it's always supposed to get a Block since it needs to generate a local variable in some scope.

Therefore it looks like this bug can more specifically be stated as: "Why is an LVD passed to internalRewriteAST instead of a Block?"

@lombokissues
Collaborator

👤 r.spilker   🕗 Feb 18, 2014 at 22:53 UTC

Refactors run on the org.eclipse.dom variant of the AST, and not the one lombok primarily works with (the internal). The dom variant has a flag called 'ORIGINAL', set on almost every node (in the 'typeAndFlags' field). The refactor scripts won't consider non-ORIGINAL nodes as places to generate code for / into.

The relevant block when using @ SneakyThrows is the (generated) braces that go with the generated 'try' statement. This block IS in the org.eclipse.dom variant, but does NOT have the ORIGINAL flag set. That seems to be the problem (it's possible that further problems will ensue when we fix this).

This bug has now been reduced to: Why is that ORIGINAL flag not set? Should we use patches to force-set it, or is there something simpler we can do to set this flag? Should we even set this flag (in many ways, it is enticing to treat generated code as not original), in which case we should patch org.eclipse.jdt.internal.core.dom.RewriteEventStore﹟isNewNode(ASTNode node) to always return 'false' is ASTNode is generated. That is a dom-style ASTNode, which has a generated $isGenerated field).

@lombokissues
Collaborator

👤 r.spilker   🕗 Feb 20, 2014 at 20:25 UTC

Fixed in c72e2a2

The fix was reverting a change from 2010.

We've created an edge release so you can try it out: https://projectlombok.org/download-edge.html

@lombokissues lombokissues removed the accepted label Jul 14, 2015
@lombokissues
Collaborator

👤 r.spilker   🕗 Feb 20, 2014 at 20:34 UTC

This fix also fixes issue #511.

@lombokissues
Collaborator

End of migration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment