Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 361920

Summary: [nls tooling][quick assist] IAE with 'Remove key' quick assist in Properties File editor
Product: [Eclipse Project] JDT Reporter: Raksha Vasisht <raksha.vasisht>
Component: TextAssignee: Markus Keller <markus.kell.r>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: daniel_megert, deepakazad, markus.kell.r
Version: 3.8Flags: daniel_megert: review+
Target Milestone: 3.7.2   
Hardware: All   
OS: All   
Whiteboard:

Description Raksha Vasisht CLA 2011-10-25 08:53:18 EDT
FUP of bug 358384

Build id : I20111021-1625(4.2) & I20111021-0800 (3.8)

Steps:

1) Add a new key value pair in PFE, save, ctrl+1 on key
2) click on 'Remove key' proposal
-> The additional info is empty except for '...' (or wrong in most cases)

3) click again -> IAE 
(if you can't reproduce in one shot, try repeating the steps a couple of times) 


java.lang.IllegalArgumentException: Argument not valid
	at org.eclipse.swt.SWT.error(SWT.java:4264)
	at org.eclipse.swt.SWT.error(SWT.java:4198)
	at org.eclipse.swt.SWT.error(SWT.java:4169)
	at org.eclipse.swt.custom.StyledText.setSelectionRange(StyledText.java:9544)
	at org.eclipse.jface.text.TextViewer.setSelectedRange(TextViewer.java:2401)
	at org.eclipse.jface.text.TextViewer$ViewerState.restore(TextViewer.java:1237)
	at org.eclipse.jface.text.TextViewer.enabledRedrawing(TextViewer.java:5096)
	at org.eclipse.jface.text.TextViewer.enabledRedrawing(TextViewer.java:5071)
	at org.eclipse.jface.text.TextViewer.setRedraw(TextViewer.java:5156)
	at org.eclipse.jface.text.TextViewer.setRedraw(TextViewer.java:5130)
	at org.eclipse.jface.text.TextViewer$RewriteTarget.setRedraw(TextViewer.java:1067)
	at org.eclipse.jface.text.TextViewer$DocumentRewriteSessionListener.documentRewriteSessionChanged(TextViewer.java:1478)
	at org.eclipse.jface.text.AbstractDocument.fireRewriteSessionChanged(AbstractDocument.java:1559)
	at org.eclipse.jface.text.AbstractDocument.stopRewriteSession(AbstractDocument.java:1648)
	at org.eclipse.core.internal.filebuffers.SynchronizableDocument.stopRewriteSession(SynchronizableDocument.java:113)
	at org.eclipse.ltk.core.refactoring.TextChange.performEdits(TextChange.java:281)
	at org.eclipse.ltk.core.refactoring.TextFileChange.access$0(TextFileChange.java:1)
	at org.eclipse.ltk.core.refactoring.TextFileChange$1.run(TextFileChange.java:275)
	at org.eclipse.ui.internal.editors.text.UISynchronizationContext.run(UISynchronizationContext.java:34)
	at org.eclipse.core.internal.filebuffers.TextFileBufferManager.execute(TextFileBufferManager.java:629)
	at org.eclipse.ltk.core.refactoring.TextFileChange.performEdits(TextFileChange.java:287)
	at org.eclipse.ltk.core.refactoring.TextChange.perform(TextChange.java:238)
	at org.eclipse.ltk.core.refactoring.CompositeChange.perform(CompositeChange.java:278)
	at org.eclipse.jdt.internal.ui.text.correction.proposals.ChangeCorrectionProposal.performChange(ChangeCorrectionProposal.java:172)
	at org.eclipse.jdt.internal.ui.text.correction.proposals.ChangeCorrectionProposal.apply(ChangeCorrectionProposal.java:101)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal(CompletionProposalPopup.java:935)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertSelectedProposalWithMask(CompletionProposalPopup.java:881)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$27(CompletionProposalPopup.java:877)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup$5.widgetDefaultSelected(CompletionProposalPopup.java:657)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:119)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:972)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:888)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:90)
	at org.eclipse.ui.internal.Workbench$3.run(Workbench.java:565)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:520)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
	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:352)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
	at java.lang.reflect.Method.invoke(Method.java:611)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:624)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:579)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1431)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1407)
Comment 1 Dani Megert CLA 2011-10-25 09:11:53 EDT
Deepak, do you have time to fix this for M3 (i.e. today or tomorrow)?
Comment 2 Deepak Azad CLA 2011-10-25 12:25:59 EDT
I quickly tried with HEAD of master and cannot reproduce the exception. Raksha, do you have a test case ? I would need messages.properties and Messages.java files.

> -> The additional info is empty except for '...' (or wrong in most cases)
I half expected bugs about exceptions in this code, as it relies on document partitioning and things can go blow up there. But I am a bit surprised by "wrong in most cases", according to me if the additional info shows up it should be correct in almost all cases.
Again, can you please share your test cases? 

(In reply to comment #0)
> 2) click on 'Remove key' proposal
Does it make a difference if you select the quick assist via keyboard instead of mouse ? (I don't think it should, but asking just to be sure.)
Comment 3 Deepak Azad CLA 2011-10-25 12:41:47 EDT
Dani, I don't think I would be able to do a complete fix by tomorrow. Ok to push this to M4? (In my opinion the quick assists fail only in rare scenarios)

Note to self: Things can blow up if a key includes special characters e.g. .(dot), or you have something like "a a = x" in one line in the properties file (the space between 2 'a's is important here).
But these are different exceptions from comment 0 and the additional info does not show up in these cases.
Comment 4 Dani Megert CLA 2011-10-25 12:45:29 EDT
(In reply to comment #3)
> Dani, I don't think I would be able to do a complete fix by tomorrow. Ok to
> push this to M4? (In my opinion the quick assists fail only in rare scenarios)
Yes. I'll take a look for M3 in case Raksha provides a test case that indicates a more frequent occurrence of the IAE.
Comment 5 Dani Megert CLA 2011-10-26 05:12:57 EDT
I was not able to trigger the IAE during my test pass.
Comment 6 Markus Keller CLA 2011-10-26 10:01:26 EDT
To reproduce, remove the last key in /org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/ExpressionMessages.properties, and then remove the next last key.
Comment 7 Markus Keller CLA 2011-10-26 12:53:11 EDT
Only seems to happen with Windows line delimiters.
Comment 8 Markus Keller CLA 2011-10-26 15:03:11 EDT
The code is a total disaster. Problems occur whenever there is whitespace around key and/or value, see the trimming in  PropertyFileDocumentModel#parsePropertyDocument(IDocument) and PropertyFileDocumentModel.KeyValuePairModell#getLength() that uses the trimmed values.

Dani, I think we should backport this to 3.7.2. I guess it only got broken in 3.7 due to bug 333631 (didn't verify this).

Fixed in master.
commit b4c16ccdb9d004714b17b3f3873ca6d1b00396e6
Comment 9 Dani Megert CLA 2011-10-27 04:17:37 EDT
(In reply to comment #6)
> To reproduce, remove the last key in
> /org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/ExpressionMessages.properties,
> and then remove the next last key.

Interesting. I can still not reproduce the IAE with those steps. I took the file from I20111025-1800 and tried with Windows and Unix LDs. What I can reproduce though is the scrambling of the file.
Comment 10 Dani Megert CLA 2011-10-27 04:43:45 EDT
(In reply to comment #8)
> The code is a total disaster.
I agree.

> Dani, I think we should backport this to 3.7.2. I guess it only got broken in
> 3.7 due to bug 333631 (didn't verify this).
Yes, I just verified this and +1 to backport. Thanks Markus for looking into it.
Comment 11 Dani Megert CLA 2011-10-27 04:46:03 EDT
Verified in I20111026-2132 that the file is no longer scrambled when removing a property. Still unable to reproduce the IAE.
Comment 12 Dani Megert CLA 2011-10-27 05:17:03 EDT
> Interesting. I can still not reproduce the IAE with those steps. I took the
> file from I20111025-1800 and tried with Windows and Unix LDs. 
My bad: I was using the latest build and this already had Markus's fix in it. So that also proofs that the fix works fine.
Comment 13 Raksha Vasisht CLA 2011-10-27 08:59:04 EDT
(In reply to comment #2)
> I quickly tried with HEAD of master and cannot reproduce the exception. Raksha,
> do you have a test case ? I would need messages.properties and Messages.java
> files.
> 
I just tried ActionMessages.java and ActionMessages.properties and also CorrectionMessages.java and CorrectionMessages.properties.

> > -> The additional info is empty except for '...' (or wrong in most cases)
> I half expected bugs about exceptions in this code, as it relies on document
> partitioning and things can go blow up there. But I am a bit surprised by
> "wrong in most cases", according to me if the additional info shows up it
> should be correct in almost all cases.
The info either shows only '...' , or some weird characters like '<br>' , or sometimes only the previous/next entry in the properties file and blank afterwards. Same test case as above. 
> 
> (In reply to comment #0)
> > 2) click on 'Remove key' proposal
> Does it make a difference if you select the quick assist via keyboard instead
> of mouse ? (I don't think it should, but asking just to be sure.)
No.
(In reply to comment #9)

> Interesting. I can still not reproduce the IAE with those steps. I took the
> file from I20111025-1800 and tried with Windows and Unix LDs. What I can
> reproduce though is the scrambling of the file.

You need to set windows delimiters and also have a space after '='. Also, the file becomes ineditable afterwards, and you need to close it and reopen to edit it again.

Verified that the fix works fine with I20111026-2132 and can longer see the IAE or additional info issue.
Comment 14 Dani Megert CLA 2011-10-31 05:45:00 EDT
Fixed in R3_7_maintenance: 4f0105ccd524752d55e59309efd792ac0037f7db
Comment 15 Dani Megert CLA 2011-12-06 04:57:01 EST
Verified in M20111128-1153.