Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 331485 - Extension editor scrambles plugin.xml
Summary: Extension editor scrambles plugin.xml
Status: VERIFIED FIXED
Alias: None
Product: PDE
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 major with 1 vote (vote)
Target Milestone: 3.7 RC1   Edit
Assignee: Dani Megert CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 77284 232692 324986 338950 340379 (view as bug list)
Depends on: 293474
Blocks: 342512
  Show dependency tree
 
Reported: 2010-11-30 19:11 EST by Eric Jain CLA
Modified: 2017-03-07 12:25 EST (History)
14 users (show)

See Also:
curtis.windatt.public: review+


Attachments
Video that shows how to reproduce the bug (384.87 KB, video/quicktime)
2011-04-28 02:56 EDT, Ralf Ebert CLA
no flags Details
Fix (2.15 KB, patch)
2011-05-06 06:00 EDT, Dani Megert CLA
no flags Details | Diff
Scrambled plugin.xml 2017.03.07 (4.46 KB, application/xml)
2017-03-07 12:14 EST, Bence Sipka CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Jain CLA 2010-11-30 19:11:27 EST
Build Identifier: I20101028-1441

When editing the extensions, I often end up with a corrupted plugin.xml, e.g. with the following last few lines:

      ...
      </menuContribution>  icon="icons/export_wiz.gif"
               style="push">
         </command>
      </menuContribution>
   </eicons/export_wiz.gifxtension>
</plugin>


Reproducible: Sometimes

Steps to Reproduce:
Not sure yet how to reproduce this issue; might be happening after copy pasting extension elements in the form editor, or perhaps after first doing some manual editing and then some more editing in the form editor.
Comment 1 Curtis Windatt CLA 2010-12-01 12:53:50 EST
This has been seen before when using cut/paste and undo/redo.  I don't believe we were ever able to track down a cause.  I couldn't find a direct dupe, though bug 324986 and 282716 may be related.
Comment 2 Miles Parker CLA 2011-02-25 18:44:57 EST
I get this all the time as well -- thought it was just me. I'm on Cocoa. It seems so random that I've also avoided reporting it, but it happens often enough that I've given up on using the PDE editor for anything but adding new elements. But it doesn't seem to be repeatable -- sometimes an edit work, other times the same kind of edit doesn't. I think I've noticed it happening more often with longer / more complex plugin.xml. Sometimes text is removed, other times text lines are duplicated, and this often but not always seem to happen along element boundaries. The really worrying/annoying thing is that sometimes the corruption can happen invisibly and it isn't discovered until later on when something in the UI doesn't work correctly.

I'd vote for high priority - certainly for Indigo, as though this has been around for a while, my guess is that it is one of those things that a lot of people have experienced but learned to live with.
Comment 3 ekkehard gentz CLA 2011-02-25 18:51:19 EST
same happens from time to time while editing ComponentDefinitions.
so before saving I always take a look at the source tab to see if something was scrambled.

happens never while creating a new one
but sometime editing properties or editing classnames etc

ekke
(In reply to comment #2)
> I get this all the time as well -- thought it was just me. I'm on Cocoa. It
> seems so random that I've also avoided reporting it, but it happens often
> enough that I've given up on using the PDE editor for anything but adding new
> elements. But it doesn't seem to be repeatable -- sometimes an edit work, other
> times the same kind of edit doesn't. I think I've noticed it happening more
> often with longer / more complex plugin.xml. Sometimes text is removed, other
> times text lines are duplicated, and this often but not always seem to happen
> along element boundaries. The really worrying/annoying thing is that sometimes
> the corruption can happen invisibly and it isn't discovered until later on when
> something in the UI doesn't work correctly.
> 
> I'd vote for high priority - certainly for Indigo, as though this has been
> around for a while, my guess is that it is one of those things that a lot of
> people have experienced but learned to live with.
Comment 4 Curtis Windatt CLA 2011-02-28 10:16:59 EST
Bumping to major.  This has been an issue in PDE for ages, but in the last release or two, people are encountering it more.  We made one fix in 3.6 that helped a lot of people (Bug 293474), but obviously we haven't fixed everything.  Unfortunately, no one has found a cause for this issue.
Comment 5 Miles Parker CLA 2011-03-02 00:01:21 EST
I just did this by taking some extension items and moving them up or down rapidly. Naturally, I did it again and everything worked perfectly. :( I would suspect some kind of threading issue -- my very speculative observation is that it seems to happen when one gets "ahead" of the UI thread.
Comment 6 Curtis Windatt CLA 2011-03-04 11:32:05 EST
*** Bug 338950 has been marked as a duplicate of this bug. ***
Comment 7 Curtis Windatt CLA 2011-03-04 11:32:52 EST
*** Bug 77284 has been marked as a duplicate of this bug. ***
Comment 8 Curtis Windatt CLA 2011-03-04 11:33:21 EST
*** Bug 232692 has been marked as a duplicate of this bug. ***
Comment 9 Curtis Windatt CLA 2011-04-14 12:20:28 EDT
*** Bug 342855 has been marked as a duplicate of this bug. ***
Comment 10 Curtis Windatt CLA 2011-04-14 12:23:36 EDT
There is an SWTBot test available on Bug 342855 to reproduce.
Comment 11 Miles Parker CLA 2011-04-14 12:58:52 EDT
Possibly related to this issue: Bug 342868 ?
Comment 12 Ralf Ebert CLA 2011-04-28 02:56:32 EDT
Created attachment 194231 [details]
Video that shows how to reproduce the bug

org.eclipse.pde.internal.ui.editor.context.XMLInputContext creates text edit operations when nodes are edited, inserted, removed, moved, .... in the Extensions tab. For this it uses offset/length of the XML document nodes, for example in #insertAfterSibling, line 140. It piles up these edit operations until the document is saved or the plugin.xml is opened. But the offset/length of the nodes used to create the edit operations is ONLY updated when the document is reconciled (on save/plugin.xml open). So when multiple edit operations pile up without saving, esp. when editing content out of order, things start to break.

It can be reproduced easily once you know that this is happening. See the attached video for an example.

I cannot believe that this was happening all the years. From looking at the code, esp. PluginInputContext#reorderInsertEdits, the authors of that code seemed to be very confident that the order of multiple edit operations does not matter. Why? Also, does it make sense to reinvent syncing text and XML model in PDE?
Comment 13 Dani Megert CLA 2011-05-03 12:11:23 EDT
I'll see whether we can find a safe fix that's appropriate for RC1.
Comment 14 Dani Megert CLA 2011-05-06 04:59:24 EDT
Steps to reproduce in I20110505-0800:

1.  create a plug-in project
2.  add the following plugin.xml:
---%<---
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension
         point="org.eclipse.ui.contexts">
      <context
            id="Bug.context2"
            name="A">
      </context>
      <context
            id="Bug.context1"
            name="B">
      </context>
   </extension>
</plugin>
---%<---
3.  save
4.  go to the 'Extensions' page
5.  expand the extension node
6.  click on node A
7.  append '1' in the name field
8.  click on node B
9.  append '2' in the name field
10. click on node A1
11. append '3' in the name field
12. switch to 'plugin.xml' tab
==> name is corrupted: name="A13>

Initial debugging shows that the model generates wrong ReplaceEdit/s.
Comment 15 Dani Megert CLA 2011-05-06 05:38:28 EDT
Test Case 2:
1.  create a plug-in project
2.  add the following plugin.xml:
---%<---
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension
         point="org.eclipse.ui.contexts">
      <context
            id="Bug.context2"
            name="A">
      </context>
      <context
            id="Bug.context1"
            name="B">
      </context>
   </extension>
</plugin>
---%<---
3.  save
4.  go to the 'Extensions' page
5.  expand the extension node
6.  click on node A
7.  delete the value (make name field empty)
8.  click on node B
9.  click on first node
11. enter '1' in the name field
12. switch to 'plugin.xml' tab
==> name is wrong: name="1A">
Comment 16 Dani Megert CLA 2011-05-06 05:41:20 EDT
Test Case 3:
1.  create a plug-in project
2.  add the following plugin.xml:
---%<---
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension
         point="org.eclipse.ui.contexts">
      <context
            id="Bug.context2"
            name="A">
      </context>
      <context
            id="Bug.context1"
            name="B">
      </context>
   </extension>
</plugin>
---%<---
3.  save
4.  go to the 'Extensions' page
5.  expand the extension node
6.  click on node A
7.  append 'foo' in the name field
8.  click on node B
9.  click on node Afoo
10. Undo (Ctrl+Z)
12. switch to 'plugin.xml' tab
==> name is corrupted
Comment 17 Dani Megert CLA 2011-05-06 05:42:07 EDT
*** Bug 324986 has been marked as a duplicate of this bug. ***
Comment 18 Dani Megert CLA 2011-05-06 05:44:21 EDT
*** Bug 340379 has been marked as a duplicate of this bug. ***
Comment 19 Dani Megert CLA 2011-05-06 06:00:54 EDT
Created attachment 194917 [details]
Fix

This patch correctly merges the text edits.
Comment 20 Curtis Windatt CLA 2011-05-06 12:09:25 EDT
+1 
Patch works great for me.  Undo/redo, stacking multiple edits, and the provided test cases all are working.  Dani, I owe you a frosty beverage for fixing this in 3.7 (and I'm probably not the only one).

Miles, Eric, et al can you please give this patch a try to verify as soon as possible?
Comment 21 Curtis Windatt CLA 2011-05-06 12:11:25 EDT
Dani, please also update the copyright on the file before committing.
Comment 22 Ralf Ebert CLA 2011-05-06 22:18:42 EDT
Yep, I cannot 'scramble' the xml manually anymore after applying the patch.

Thanks, this is great!

Unfortunately, it does not fix the scrambling shown by my SWTBot test in bug 342855 (which just adds new extensions and saves at random in a loop). I experimented a bit more and this 2nd issue seems to be related to editing right after saving, I can make the test work by adding a sleep(2000) after saving. I cannot reproduce that manually though, but the SWTBot case breaks all the time after doing 10-20 operations. Now, when I save the document, I see the extension tree updated immediately, but the whole content seems to be updated asynchronously after some time again (one can tell because the cursor/selection changes in an active attribute field). Could this be related?

Also, looking at the patch I learned that I was wrong about the cause for the issue, so answering my own question, 'Why?' does the order of the operations/using not-up-to-date document offset/length does not matter: all edit operations are merged together in InputContext#flushModel into one edit operation.
Comment 23 Dani Megert CLA 2011-05-07 02:42:34 EDT
Committed fix to HEAD with updated copyright date.

> Unfortunately, it does not fix the scrambling shown by my SWTBot test in bug
> 342855
Reopened bug 342855 as the fix here does not solve this issue.
Comment 24 ekkehard gentz CLA 2011-05-07 03:38:30 EDT
(In reply to comment #20)
...
>Dani, I owe you a frosty beverage for fixing this
> in 3.7 (and I'm probably not the only one).
> 
+1 beer from me

> Miles, Eric, et al can you please give this patch a try to verify as soon as
> possible?

works great :)
Comment 25 Miles Parker CLA 2011-05-07 12:20:41 EDT
(In reply to comment #24)
> (In reply to comment #20)
> ...
> >Dani, I owe you a frosty beverage for fixing this
> > in 3.7 (and I'm probably not the only one).
> > 
> +1 beer from me
> 
> > Miles, Eric, et al can you please give this patch a try to verify as soon as
> > possible?
> 
> works great :)

I'll give it a shot in next few days.
Comment 26 Curtis Windatt CLA 2011-05-16 16:39:32 EDT
Verified in I20110514-0800

Please keep your eyes out for any other odd behaviour in the editors.
Comment 27 Greg Watson CLA 2011-05-19 19:00:29 EDT
I have encountered another issue that corrupts the plugin.xml. It appears that the escaping of certain special characters does not work properly. 

I don't have a test case, but you can try it out by creating an extension point that has a string field. Try creating and extension and entering some text in the field that contains special characters such as ", ', ;, etc. The initial conversion seems to work ok, but if you subsequently edit the string (remove a special character, add new ones, etc.) the field is eventually corrupted. Just play around a bit and you should see it.
Comment 28 Greg Watson CLA 2011-05-19 19:18:11 EDT
It seems particularly vulnerable when adding/inserting a semicolon in the string if it already contains escaped characters. So if a string contains 'foo' (including the single quotes), then adding a semicolon to the end seems to corrupt it.
Comment 29 Dani Megert CLA 2011-05-20 01:44:06 EDT
Greg, can you please open a new bug with the issue you see? We can't use this bug to handle ever newly detected case.
Comment 30 Greg Watson CLA 2011-05-20 08:43:45 EDT
Opened bug 346665
Comment 31 Bence Sipka CLA 2017-03-07 12:14:26 EST
Created attachment 267145 [details]
Scrambled plugin.xml 2017.03.07

I have this issue as well now. I was also copy pasting extension elements and used undo-redo. The resulting plugin.xml became scrambled and the editor wasn't able to parse it anymore, resulting in DOM exception.

Eclipse version 4.6.2 neon.2 Build ID: M20161124-1400
Comment 32 Mickael Istria CLA 2017-03-07 12:21:14 EST
Should we reopen the issue here according to Bence comment, or create a new one?
Comment 33 Dani Megert CLA 2017-03-07 12:22:34 EST
(In reply to Mickael Istria from comment #32)
> Should we reopen the issue here according to Bence comment, or create a new
> one?

As usual: open a new bug report with steps to reproduce.
Comment 34 Mickael Istria CLA 2017-03-07 12:25:08 EST
(In reply to Dani Megert from comment #33)
> (In reply to Mickael Istria from comment #32)
> > Should we reopen the issue here according to Bence comment, or create a new
> > one?
> 
> As usual: open a new bug report with steps to reproduce.

Ok.
@Bence: can you please do that?