Bug 293474 - Editing extensions in PDE editor creates invalid plugin.xml
Summary: Editing extensions in PDE editor creates invalid plugin.xml
Status: RESOLVED FIXED
Alias: None
Product: PDE
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.6   Edit
Hardware: PC All
: P2 major (vote)
Target Milestone: 3.6 M7   Edit
Assignee: PDE-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
: 298802 (view as bug list)
Depends on:
Blocks: 331485
  Show dependency tree
 
Reported: 2009-10-27 13:09 EDT by Paul Webster CLA
Modified: 2011-02-28 10:16 EST (History)
16 users (show)

See Also:


Attachments
Extensions tab (219.84 KB, image/png)
2009-10-27 13:09 EDT, Paul Webster CLA
no flags Details
plugin.xml tab (225.57 KB, image/png)
2009-10-27 13:10 EDT, Paul Webster CLA
no flags Details
Errors from the PDE Editor (16.28 KB, text/plain)
2009-12-07 13:12 EST, Paul Webster CLA
no flags Details
Exceptions before saving changed extensions (11.55 KB, text/plain)
2009-12-12 08:27 EST, Ralf Ebert CLA
no flags Details
one part fix (1.71 KB, patch)
2010-03-15 17:04 EDT, Michael Rennie CLA
no flags Details | Diff
Updated fix (2.74 KB, patch)
2010-03-16 13:02 EDT, Curtis Windatt CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Webster CLA 2009-10-27 13:09:55 EDT
Created attachment 150655 [details]
Extensions tab

I was editing a new plugin in the Extensions tab and saving it as I go.  I
ended up in the state where it had created an invalid plugin.xml

PW
Comment 1 Paul Webster CLA 2009-10-27 13:10:37 EDT
Created attachment 150656 [details]
plugin.xml tab
Comment 2 Paul Webster CLA 2009-10-27 13:19:12 EDT
Build: I20091027-0100

The PDE editor is munging quite a bit of the plugin.xml.  I added a separator and then dragged it to be between my third and fourth child at that level.  It inserted the <separator id="what" visible="false"></separator> in the middle of the  attributes of the 3rd and 4th children, rendering the XML invalid.

PW
Comment 3 Curtis Windatt CLA 2009-10-28 15:05:29 EDT
Needs investigation
Comment 4 Paul Webster CLA 2009-11-05 15:03:44 EST
This also effects the DS editor:
org.eclipse.pde.ds.ui.editor

It inserted a property in the middle of a closing tag.

PW
Comment 5 Paul Webster CLA 2009-12-07 08:13:16 EST
The PDE Editor has been corrupting the XML for an entire milestone now, this urgently needs to get fixed.

PW
Comment 6 Remy Suen CLA 2009-12-07 12:44:22 EST
I hit this last Friday and am hearing reports on IRC.
Comment 7 Paul Webster CLA 2009-12-07 13:12:34 EST
Created attachment 153946 [details]
Errors from the PDE Editor

I got these errors from the PDE editor while trying to reproduce the problem.

PW
Comment 8 Paul Webster CLA 2009-12-07 13:20:00 EST
OK, I'm working on org.eclipse.ui.tests/plugin.xml (from HEAD/platform-ui-tests)

Add org.eclipse.ui.menus EP at the end of the file, add a menuContribution, to that add a couple of commands and a menu in the middle, to the menu add a couple of commands and a menu in the middle.

save


Switch to plugin.xml and delete the innermost <menu>...</menu> block and save.

Switch back to Extensions and that block is still displayed.  If you update parts of the extension after that block (and sometimes before) it will potentially slice out parts of your XML or corrupt it.  I got:

         <command
               commandId="org.e<command
                     commandId="org.eclipse.ui.tests.command42"
                     id="Y"
                     label="Y"
                     mnemonic="Y"
                     style="push">
         </command>

PW
Comment 9 Paul Webster CLA 2009-12-07 13:21:34 EST
This time the error was accompanied by some sysout:

 Error:  Could not parse XML contribution for "org.eclipse.ui.tests//home/users/pwebster/down/tmp_360/org.eclipse.ui.tests/plugin.xml". Any contributed extensions and extension points will be ignored.

PW
Comment 10 David Carver CLA 2009-12-07 13:35:15 EST
if I'm not mistaken PDE XML editors are using string concatination to create the XML. Anybody know when this started happening, we might be able to track it back to a particular code change.
Comment 11 Boris Bokowski CLA 2009-12-07 13:36:41 EST
Happens on Windows too.
Comment 12 Boris Bokowski CLA 2009-12-07 13:42:00 EST
(In reply to comment #10)
> if I'm not mistaken PDE XML editors are using string concatination to create
> the XML. Anybody know when this started happening, we might be able to track it
> back to a particular code change.

It looks like the PDE projects are now mirrored as Git repositories (see http://dev.eclipse.org/git/) - I can recommend using "git bisect" for finding the offending commit. Use a Mac or a Linux box for this to make it easy to install the git command line client. For a success story with "git bisect", see http://jbowes.wordpress.com/2007/02/18/git-bisect-a-practical-example-with-yum/
Comment 13 Curtis Windatt CLA 2009-12-09 11:45:03 EST
Moving to M5.  We have not been able to reproduce and haven't found any possible causes yet.
Comment 14 Ralf Ebert CLA 2009-12-12 08:27:56 EST
Created attachment 154363 [details]
Exceptions before saving changed extensions

I just got the attached AssertionFailedException and MalformedTreeException in M4 before saving changed extension elements. These look a bit like they could be responsible for corrupting a document.
Comment 15 Curtis Windatt CLA 2010-01-05 09:45:39 EST
*** Bug 298802 has been marked as a duplicate of this bug. ***
Comment 16 David Carver CLA 2010-01-05 09:53:55 EST
One of the ways i was able to reproduce this was by positining the cursor in the plugin.xml tab with in some XML text, then going to the Extension point tab, and adding some extensions.  When I went back to the plugin.xml tab, it had inserted the extension point code where the cursor was, not where the extension point updates were to occur.
Comment 17 Lars Vogel CLA 2010-01-05 10:02:16 EST
To reproduce try the following:

Create new plugin project "de.vogella.pdebug".

Add dependency to "org.eclipse.core.runtime".

Using the "Extensions" tab add extension "org.eclipse.core.runtime.products"
with application="org.eclipse.e4.ui.workbench.swt.E4Application" 
name="My App". Add property "appName" with any value.

Stop and check the plugin.xml -> You have several times
"org.eclipse.core.runtime.products" included.
------------

Works everytime for me (in the sense that plugin.xml is corrupted).
Comment 18 Curtis Windatt CLA 2010-01-05 10:38:49 EST
Tried Lars steps and also tried Dave's suggestion of moving the cursor around.  Couldn't reproduce in I20091217-0819 or in a workbench running on PDE Head.  I wasn't seeing any collapsing in the tree either (the two problems feel related).

What VMs are people using?
Comment 19 Chris Aniszczyk CLA 2010-01-05 10:44:08 EST
This is one of the two famous "ghost in the machine" bugs in PDE.

The editor code hasn't changed much for awhile.

I have trouble reproducing this bug also. I know it exists though :)
Comment 20 Lars Vogel CLA 2010-01-05 10:45:07 EST
I'm using java version "1.6.0_17".

Shall I do a screencast to demonstrate how I do it?
Comment 21 David Carver CLA 2010-01-05 12:36:35 EST
(In reply to comment #18)
> Tried Lars steps and also tried Dave's suggestion of moving the cursor around. 
> Couldn't reproduce in I20091217-0819 or in a workbench running on PDE Head.  I
> wasn't seeing any collapsing in the tree either (the two problems feel
> related).
> 
> What VMs are people using?

I'm running on Ubuntu Linux Karmic Koola, with Sun Java 6 jvm.   I've given up trying to use the UI and just using the painful plugin.xml editor directly (really wish this leverage wtp's xml editor).  Only if I start using the UI does the XML get messed up.
Comment 22 Paul Webster CLA 2010-01-05 13:01:26 EST
(In reply to comment #18)
> Tried Lars steps and also tried Dave's suggestion of moving the cursor around. 
> Couldn't reproduce in I20091217-0819 or in a workbench running on PDE Head.  I
> wasn't seeing any collapsing in the tree either (the two problems feel
> related).
> 
> What VMs are people using?

I'm on linux (FC10 at home and RHEL5.3 at work) and I'm using the IBM JDK 1.5 when I see it.

PW
Comment 23 Lars Vogel CLA 2010-01-05 14:00:34 EST
I uploaded a screencast which shows the problem to my server. This can be found here: http://www.vogella.de/temp/pdebug.avi
Comment 24 Lars Vogel CLA 2010-01-07 10:46:41 EST
In addition I can offer a remote (debugging) session to demonstrate this bug; I can easily reproduce it.
Comment 25 moonese CLA 2010-01-21 01:29:45 EST
I also have the same problem which give me much trouble, I am using:

Eclipse:  3.6 M1 -> M4, 
JDK:      1.6.0_18
Platform: Windows XP

I tried the latest 3.5.2RC1, the Plug-in Manifest Editor just works fine, 
This problem is only on Eclipse 3.6, and remains unfixed through M1 to M4.
Comment 26 Lothar Werzinger CLA 2010-02-16 17:05:38 EST
This bug is biting us big time. I hope there is a solution soon.
Comment 27 Jon Sorensen CLA 2010-02-16 20:36:03 EST
This feature is radio-active and fails with minimal interaction. Please fix it soon since the work-around is tedious and time consuming. Many thanks in advance.
Comment 28 Darin Wright CLA 2010-03-12 09:20:17 EST
Moving to major. Paul hasn't seen the problem recently and the PDE team has not been able to reproduce it. Paul will attempt to reproduce next week, and if possible, we'll remotely debug the problem.
Comment 29 Lars Vogel CLA 2010-03-12 15:46:51 EST
Let me know if you need help; until now I can easily reproduce this.
Comment 30 Michael Rennie CLA 2010-03-15 17:04:44 EDT
Created attachment 162109 [details]
one part fix

I managed to reproduce this consistently.

I found that in the the case of an attribute replace the length of the text being replace was always set to be the length of the new (replacement) string. This works fine, except when the new attribute is shorter than the original, then you get messed up attribute strings.

Steps (that worked for me):

1. add an adapter factory extension
2. change it a few times saving between the changes
3. press undo more than once (without saving inbetween)
4. save.

Expected: all is well.

Happens: XML is hosed, there may not be an error, depending on what you changed, but if you changed attributes

At this point switching to the XML text section and pressing undo (until the XML looks sane) would fix the problem for me.
Comment 31 Michael Rennie CLA 2010-03-15 17:07:41 EDT
(In reply to comment #30)
> I managed to reproduce this consistently.

looks like we need to do a pass through the code and find all usage of ReplaceEdit and make sure the offset / lengths are correct.
Comment 32 Curtis Windatt CLA 2010-03-15 17:09:53 EDT
PDE is using ReplaceEdit incorrectly in a number of classes, passing the length of the new text rather than the length of the text to replace.  I will look at a broader fix.  However, the PDE code has been like this for some time (years), so I don't know why this is being seen more now.
Comment 33 Curtis Windatt CLA 2010-03-16 13:02:52 EDT
Created attachment 162184 [details]
Updated fix

I went through all the places that PDE uses ReplaceEdit.  At first glance they appeared to be incorrect, but in several cases the node has the correct old length stored.  Calling ReplaceEdit(node.getOffset, node.getLength, node.write) is valid because getLength returns a stored int, not the length of the node.write string.

XMLInputContext was the only place that I debugged through where the lengths are incorrect.
Comment 34 Curtis Windatt CLA 2010-03-16 13:06:54 EDT
I have committed the fix to HEAD.

There were two places I wasn't able to debug to where there could still be a problem.  In XMLInputContext#addElementContentOperation (I don't know of anywhere in the PDE editors that we add text content to an element).  The other is XMLTextChangeListener, which is used in the tests and a utility class, but I wasn't able to hit the specific code path using ReplaceEdit.  After debugging the other cases, I feel reasonably confident that the length is being used correctly in those cases.
Comment 35 Lars Vogel CLA 2010-03-16 13:20:34 EDT
@Curtis: Thanks. Do you know if this will be picked up by the next e4 milestone build? If yes, I can test this fix easily.
Comment 36 Paul Webster CLA 2010-03-16 13:25:33 EDT
(In reply to comment #35)
> @Curtis: Thanks. Do you know if this will be picked up by the next e4 milestone
> build? If yes, I can test this fix easily.

It'll show up next Wed or Thurs (in the middle of eclipsecon :-)

PW