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

Bug 325981

Summary: Code Formatter randomly eats code when typing
Product: z_Archived Reporter: brad n <bradn>
Component: PDTAssignee: PHP Core <php.core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: critical    
Priority: P1 CC: bradn, fmmarzoa, freevo, ganoro, jonas.olstad, pless84, robert.munteanu, rulatir, xeorem, zhaozhongwei, zulus
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   
Whiteboard:
Attachments:
Description Flags
After bug happens code is deleted by a verticle margin
none
eclipse feature list
none
eclipse error log none

Description brad n CLA 2010-09-22 11:48:44 EDT
Build Identifier: 20100617-1415

When using the new version of Eclipse, on 7 different PCs running XP, vista, and 7, using Eclipse to write PHP code can irreversibly damage php files.  It starts with making half the code disappear, either horizontally or vertically it seems to be inconsistent.  You then have to close the file and reopen it to be able to type anything and watch it fail again.  The big issues with this is it will destroy the code, then save the file after you have specified NO.  In some rare cases the file becomes so corrupted Eclipse crashes immediately when opening (often times when opening Eclipse itself as the file is loaded int he workbench)

This seems to be reproducible 100% by writing PHP code.  Nothing special.  It also seems to store whatever is messing it up in meta data, as a file will become progressively more problematic (sometimes you can get 30-40 lines in before it eats your code progressing to anything you type causes it to start eating).  Sometimes copying the contents to notepad, deleting the file, then creating a new file with the same name and pasting the contents back from notepad will fix it for a few hours.  Extremely frustrating to loose a page of code because you used your editor to try and edit it.

Reproducible: Always

Steps to Reproduce:
1. Use Eclipse for PHP
2.
3.
Comment 1 brad n CLA 2010-09-22 12:01:45 EDT
Created attachment 179391 [details]
After bug happens code is deleted by a verticle margin

As you can see the line numbers have disappeared, and the first 4 left most characters on EVERY line have been deleted.  Closing Eclipse and telling it NOT to save results in the file saving with deleted information.  Yes, Saying "DO NOT SAVE" results in the file being saved.  Trying to undo the "Eat my code" operation returns the shown error.  This was caused by typing "if(", I didn't even get to complete the block before it destroyed everything.
Comment 2 Roy Ganor CLA 2010-09-27 04:29:43 EDT
Can you tell what version of PDT you use? from eclipse.org/downloads?
Comment 3 Zhongwei Zhao CLA 2010-09-27 06:43:38 EDT
and it is better to have a sample file,thanks!
Comment 4 brad n CLA 2010-09-27 12:27:37 EDT
  Eclipse IDE for PHP Developers	1.3.0.20100617-0520	epp.package.php

      PHP Development Tools (PDT) SDK Feature	2.2.0.v20100519-1400-53-84QAN2IGRoLXQNHWOXe1La9Od	org.eclipse.php.sdk.feature.group

I use the Eclipse IDE for PHP downloaded from eclipses homepage.  The PHP tools came prebundled, and do not appear to have any update available (through eclipse manager).  I will attach a sample file later, as I've removed Eclipse so it doesn't get accidently used and caused problems.  We've gone back to Zend 7, which uses the previous release of PDT and does not have these same problems.
Comment 5 jonas.olstad CLA 2011-07-21 07:46:27 EDT
Experiencing the same problem as described, using Eclipse with PDT.

My configuration:
Linux Mint 11
Eclipse 3.7.0 (build: I20110613-1736)

PHP Development Tools (PDT) SDK Feature	3.0.0.v20110516-1100-77--84_23JBVgSVXO7XGJz0VLa9O	org.eclipse.php.sdk.feature.group	Eclipse.org

I have managed to ALWAS REPRODUCE this bug by doing the following:

1. Create a .php file with a <?PHP (start PHP-directive), and some php-code. 
2. Verify that the PHP-file you created runs as expected.
3. Insert some empty lines before the <?PHP directive.
4. Start entering an HTML-tag, such as <!-- on the line above the <?PHP tag.
5. Line numbers are disappearing, and random fragments of texts disappears from your code....

What is causing this?
I think, for some reason, this combination of code somehow triggers the Undo-buffer, and corrupts this in some way. The result appears on the screen as line numbers and code fragments disappearing.

Normally, you can fix this by closing the source-file, without saving it, and then re-open the file and proceed with your work. Today this became a nightmare, when Eclipse denied me closing the file. I had to kill the Eclipse process in order to continue my work. 

Needless to say- FIX IT IMMEDIATELY!
Comment 6 Roy Ganor CLA 2011-08-30 07:07:23 EDT
According to your description, it seems like out of memory problem or a bad integrated environment (DLTK and PDT versions).

Since we can't reproduce this, could you please:
1. Send the .log file of your environment after this happens
2. Send the configuration details of your eclipse (so we know what versions of WTP/DLTK/PDT you have installed in your environment)
Comment 7 Frivalszky Péter CLA 2011-09-14 05:22:36 EDT
Created attachment 203322 [details]
eclipse feature list

Same problem here. Line number are disappearing, my code gets screwed up (randomly inserted spaces, disappearing lines etc. and the file is automatically saved without any questions). 

I use Indigo with the following plugins: 
Eclipse EGit 1.0.0
Eclipse SDK 3.7.0
PDT All-in-One 3.0.0 (which includes PDT Mylyn feature)
PDT SDK Feature (maybe this one is already installed within the All-in-one SDK but I had no problems so far)

I attached my configuration file (exported from the Installation Details / Configuration window) and I am going to attach today's error log. The relevant part starts somewhere aroung 10:45 when I started running into this bug again. 

I don't know if you could reproduce this but what I did was the following:

I opened a .php file which had numerous pure HTML sections in it (the php sections are separated by <?php ?> tags. 

I created a new HTML secion in the middle of the file by closing and reopening a php tag. I insterted a couple of new lines between the ?><?php tags and I started writing HTML code. 

Then I tried to open a new <div> tag. After I typed the first <, the < character did not even appear. I tried to write the 'div' after the missing < anyway, and that's when my code got screwed up. I tried to redo it again a couple of times. After I press <, the code completion list does not even appear in most of the cases, and nothing happens even if I press ESC or backspace or whatever, instead of writing the div and the rest of the HTML code.  

I went into preferences and turned off HTML code completion to see what happens. The bug was still there. If I open a new PHP or HTML file and just try to write some code (mixing php and pure html again) everything works just fine. The code completion list does not appear (just as expected). 
This is not the case in the aforementioned PHP file where the code completion list does appear sometimes, even if it was turned off in the preferences (my project settings do not  overridde this in any way). 

This does not seem to be a problem with my local settings, and not even a memory problem (I constantly watch my heap status, nothing strange in there). I have a capable PC with enough RAM and MHz.

If this isn't helping, I will try to create a sample file for you, but I will have to strip most of my code for that for legal reasons, and I do not want to do that if not necessary.
Comment 8 Frivalszky Péter CLA 2011-09-14 05:23:35 EDT
Created attachment 203323 [details]
eclipse error log

this is my error log for my previous comment
Comment 9 Frivalszky Péter CLA 2011-09-14 05:33:06 EDT
One more thing: 

If I lift (Ctrl-A, Ctrl-C, Ctrl-V) the ominous PHP code out of my project into a new, untitled, unsaved PHP file, the problem reoccurs again. Therefore I believe it does not have anything to do with my project settings or validation or project building or DLTK indexing or whatever.
Comment 10 Anthony Reyes CLA 2011-09-15 13:57:26 EDT
Same thing happens to me but I've narrowed it down to the exact case. I filed duplicate to this bug a few weeks back, not having seen this one. I'll rewrite repro steps here. This bug only happens when editing a PHP file that uses Unix Line Endings so it's no wonder the developers have had such a hard time reproducing it.

Steps for Reproduction:

1) Open any PHP file with Unix-style line endings. Alternatively, open any PHP
file and convert line-endings to Unix-style (File->Convert Line Delimiters
To->Unix). Make sure the file is not empty and has at least one newline in it
or Eclipse will automatically assume Windows style endings for you.

2) Find (or add) any PHP tag on its own line.

3) Move cursor to beginning of PHP tag and press Return to move it down a line

4) Move cursor to empty line above the PHP tag and try to open a new tag by
typing the less-than character (it will not show up).

5) Proceed to edit the file. The bug should be reproduced now.

Eclipse prints several errors to its error logs after this bug is activated. I have included the first one below. The rest of it can be found as an attachment in the other bug I filed (https://bugs.eclipse.org/bugs/show_bug.cgi?id=356701)

java.lang.Error: Error: could not match input
	at org.eclipse.wst.xml.core.internal.parser.XML10Names.zzScanError(XML10Names.java:473)
	at org.eclipse.wst.xml.core.internal.parser.XML10Names.isValidXML10Name(XML10Names.java:588)
	at org.eclipse.wst.xml.core.internal.parser.XML10Names.isValidXML10Name(XML10Names.java:271)
	[...Stack Continues...]
Comment 11 Anthony Reyes CLA 2011-09-15 13:58:13 EDT
*** Bug 356701 has been marked as a duplicate of this bug. ***
Comment 12 Francisco Marzoa CLA 2012-01-19 03:52:55 EST
I can confirm this also happens on Ubuntu Linux 11.10.

Eclipse Platform
Version: 3.7.0
Build id: I20110613-1736

PDT
3.0.0.v20110516-77-84_23JBVgSVXO7XGJz0VLa9O

It seems to be often with files that has partial html code with open tags, you know, splitting the whole doc into header.php, body.php,footer.php or something similar.
Comment 13 Szczepan Holyszewski CLA 2012-01-24 05:39:17 EST
Confirmed on Arch Linux, same symptom: trying to write HTML between ?> and <?php breaks the editor. Upvoted.
Comment 14 Szczepan Holyszewski CLA 2012-01-24 05:42:57 EST
Wait, this showstopper is fifteen months old? Reported: 2010-09-22 11:48 EDT. Hard to believe!
Comment 15 Dawid Pakula CLA 2014-02-17 01:16:29 EST
We no longer use old formatter (thank you Zend ;) ).

See bug #407768