Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quickfix "Extract to local Variable": sometimes creates "MISSING()" #1136

Closed
jukzi opened this issue Jan 26, 2024 · 12 comments
Closed

Quickfix "Extract to local Variable": sometimes creates "MISSING()" #1136

jukzi opened this issue Jan 26, 2024 · 12 comments
Assignees
Labels
bug Something isn't working regression Regression defect
Milestone

Comments

@jukzi
Copy link
Contributor

jukzi commented Jan 26, 2024

i have seen such behavior multiple times in the last weeks.
here is a reproducer:
in org.eclipse.jdt.internal.core.JavaElement.hashCode() extract the value:
image

image

sometimes also paired with BadLocationException ( but i am more concerend about the wrong source code generated):

org.eclipse.jface.text.BadLocationException
	at org.eclipse.jface.text.link.LinkedPositionGroup.enforceDisjoint(LinkedPositionGroup.java:162)
	at org.eclipse.jface.text.link.LinkedPositionGroup.addPosition(LinkedPositionGroup.java:127)
	at org.eclipse.jdt.internal.ui.viewsupport.LinkedProposalModelPresenter.enterLinkedMode(LinkedProposalModelPresenter.java:100)
	at org.eclipse.jdt.internal.ui.text.correction.proposals.LinkedCorrectionProposal.performChange(LinkedCorrectionProposal.java:186)
	at org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal.apply(CUCorrectionProposal.java:230)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal(CompletionProposalPopup.java:1004)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertSelectedProposalWithMask(CompletionProposalPopup.java:951)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.verifyKey(CompletionProposalPopup.java:1395)
	at org.eclipse.jface.text.contentassist.ContentAssistant$InternalListener.verifyKey(ContentAssistant.java:829)
	at org.eclipse.jface.text.TextViewer$VerifyKeyListenersManager.verifyKey(TextViewer.java:480)
	at org.eclipse.swt.custom.StyledTextListener.handleEvent(StyledTextListener.java:68)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4273)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1066)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1090)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1075)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:778)
	at org.eclipse.swt.custom.StyledText.handleKeyDown(StyledText.java:5742)
	at org.eclipse.swt.custom.StyledText.lambda$28(StyledText.java:5426)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4273)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1066)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1090)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1075)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1117)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1113)
	at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1594)
	at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:4866)
	at org.eclipse.swt.widgets.Canvas.WM_CHAR(Canvas.java:345)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4744)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:340)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5039)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(Native Method)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1151)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1042)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:152)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:648)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:555)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:173)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:208)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:143)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:109)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:439)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:271)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:651)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:588)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1459)

the source code generated also varies. I tried "rebuild index" and do it again while indexing resulted in (UI freeze and) another order:
image

Then i tried it again - sucess:
image

tried it again - error again (indexing did not help!):
image

that hurts

@jukzi jukzi added bug Something isn't working regression Regression defect labels Jan 26, 2024
@jukzi
Copy link
Contributor Author

jukzi commented Jan 26, 2024

eclipse.buildId=4.31.0.I20240124-1800
java.version=21.0.2

@jjohnstn jjohnstn self-assigned this Jan 26, 2024
@jjohnstn
Copy link
Contributor

I'll look at it.

@laeubi
Copy link
Contributor

laeubi commented Jan 31, 2024

I noticed that as well but as described it sometimes works and sometimes not even for the same code....

@laeubi
Copy link
Contributor

laeubi commented Jan 31, 2024

Here is even a video:

#988

@jukzi
Copy link
Contributor Author

jukzi commented Jan 31, 2024

Another variant where literally nothing is inserted instead (reproducible eclipse.buildId=4.31.0.I20240130-1800):
image
=>
image

with another exception logged:

java.lang.IllegalStateException: must specify at least one linked position
	at org.eclipse.jface.text.link.LinkedModeModel.enforceNotEmpty(LinkedModeModel.java:530)
	at org.eclipse.jface.text.link.LinkedModeModel.install(LinkedModeModel.java:484)
	at org.eclipse.jface.text.link.LinkedModeModel.forceInstall(LinkedModeModel.java:441)
	at org.eclipse.jdt.internal.ui.viewsupport.LinkedProposalModelPresenter.enterLinkedMode(LinkedProposalModelPresenter.java:109)
	at org.eclipse.jdt.internal.ui.text.correction.proposals.LinkedCorrectionProposal.performChange(LinkedCorrectionProposal.java:191)
	at org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal.apply(CUCorrectionProposal.java:228)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal(CompletionProposalPopup.java:1004)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertSelectedProposalWithMask(CompletionProposalPopup.java:951)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup$3.widgetDefaultSelected(CompletionProposalPopup.java:697)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:123)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4273)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1066)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4071)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3659)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1151)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1042)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:152)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:645)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:552)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:173)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:208)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:143)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:109)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:439)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:271)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:651)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:588)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1459)

@jjohnstn
Copy link
Contributor

My research so far is frustrating. The problem does not occur when I debug and appears to be a timing issue. I can recreate in an I-build and via remote debugging I can catch the BadLocation being thrown. The error is occurring adding the linked positions for the additional names that are offered for the new variable declaration (in LinkedProposalModelPresenter.enterLinkedMode()).

jjohnstn added a commit to jjohnstn/eclipse.jdt.ui-1 that referenced this issue Feb 1, 2024
- add missing synchronization for getCurrentChange() which accesses
  fChange which is created in a synchronized method
- potential fix for eclipse-jdt#1136
jjohnstn added a commit that referenced this issue Feb 2, 2024
- add missing synchronization for getCurrentChange() which accesses
  fChange which is created in a synchronized method
- potential fix for #1136
@jjohnstn
Copy link
Contributor

jjohnstn commented Feb 5, 2024

I believe this is fixed now. I tested with I20240203 and was unable to create the problem. Although the hashCode() method has changed from the original example, I restored it back to the original code for the test. The error occurred for me when hitting enter quickly before the preview was calculated for the extract to local variable (replace all) or extract to local variable for the given method call. If the clicking is delayed or the code debugged with breakpoints, the error did not occur. There appears to be a significant time in calculating the extract to local variable (replace all) and this assist should have its relevance lowered below the single extract (in one instance I got a UI delay registered, but the assist worked successfully). I am going to mark this closed and if a new example causes the BadLocationException, I suggest a new issue with a new scenario. Fixed by #1162

@jjohnstn jjohnstn closed this as completed Feb 5, 2024
@jjohnstn jjohnstn added this to the 4.31 M3 milestone Feb 5, 2024
@jukzi
Copy link
Contributor Author

jukzi commented Feb 6, 2024

With I20240204 i can still reproduce
#1136 (comment)
Either reopen this or duplicate that comment to new issue?

@jukzi jukzi reopened this Feb 6, 2024
@jjohnstn
Copy link
Contributor

jjohnstn commented Feb 6, 2024

@jukzi I can reproduce. I think this is a separate issue with the code not prepared to handle a conditional statement. I will investigate.

@jjohnstn
Copy link
Contributor

jjohnstn commented Feb 7, 2024

@jukzi This is definitely a separate issue. The ExtractTempRefactoring code will sometimes not be done because the expression should not be moved before the statement it is in. For example, when you have a conditional, the method call in the false path moved before the conditional might change the result of the condition test. The refactoring is figuring this out in final conditions. The QuickAssistProcessor is only checking the initial conditions and creating a proposal that wraps the refactoring. There needs to be a check so that the proposal is not offered to the end-user. I have a patch for this but need to add the same logic for extract constant which also wraps a refactoring.

@jjohnstn
Copy link
Contributor

jjohnstn commented Feb 7, 2024

See #1176

@jjohnstn
Copy link
Contributor

jjohnstn commented Feb 7, 2024

Closing this with #1177 merged.

@jjohnstn jjohnstn closed this as completed Feb 7, 2024
@jjohnstn jjohnstn moved this to Done in Java Tooling Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regression Regression defect
Projects
None yet
Development

No branches or pull requests

3 participants