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

Bug 45566

Summary: [typing] Java Editor produces whitespace garbage
Product: [Eclipse Project] JDT Reporter: Alexander Veit <lbloom>
Component: TextAssignee: JDT-Text-Inbox <jdt-text-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3    
Version: 3.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Alexander Veit CLA 2003-10-25 18:14:39 EDT
Source files get enriched with nasty whitespace while editing them with Eclipse.
It seems to originate mainly from the smart indentation feature (as well as 
from the programmers' sloppiness).
This little deficiency turns out to be really bad when many programmers work on 
the same project that is backed by a source code management system 
(particularly when different editors are used). Then differences between 
revisions tend to consist of whitespace.
However trimming trailing whitespace from each line when saving a file would 
minimize the problem.
Comment 1 Dani Megert CLA 2003-10-27 03:34:25 EST
Could you please add concrete examples/bug reports where you see this happening
and also tell us which build.

Set bug resolution from REMIND back to open once you added this information.
Comment 2 Alexander Veit CLA 2003-10-27 14:06:32 EST
The phenomenon can be studied in Eclipse versions from about 2.0 up to the 
latest Builds.

As a rule of thumb, the higher the source file's revision number is, the more 
of this ws gets into it. It spawns like rabbits :-)

A simple example:

class A
{
   void f()
   {
       Object l_obj;| <- The caret is here. Now press <return>.
   }
}

=>

class A
{
   void f()
   {
       Object l_obj;
_______<- Eclipse has inserted whitespace for indentation (indicated by _) here
   }
}

Now once again hit <return>.

The inserted whitespace will stay on the empty line forever unless you delete 
it by hand or you open the file in an editor thet strips off trailing 
whitespace on each line.

Here are some of my code formatter properties:

org.eclipse.jdt.core/org.eclipse.jdt.core.formatter.newline.emptyBlock=do not 
insert
org.eclipse.jdt.core/org.eclipse.jdt.core.formatter.lineSplit=120
org.eclipse.jdt.core/org.eclipse.jdt.core.codeComplete.fieldPrefixes=m_
org.eclipse.jdt.core/org.eclipse.jdt.core.formatter.newline.openingBrace=insert
org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=w
arning
org.eclipse.jdt.core/org.eclipse.jdt.core.formatter.newline.controlStatement=ins
ert
org.eclipse.jdt.core/org.eclipse.jdt.core.formatter.space.castexpression=do not 
insert

Comment 3 Dani Megert CLA 2003-10-28 05:12:05 EST
void f()
   {
       Object l_obj;
_______<- Eclipse has inserted whitespace for indentation (indicated by _) here
   }
}

Now once again hit <return>.
Would you expect this:
void f()
   {
       Object l_obj;
<no spacing>
<caret at beginning of line>
   }
}

And then you manually add the Tab or it jumps autmatically to the correct
indentation when typing? The first solution is not "smart typing" and the other
one would be too noisy in the UI.

If you don't like the smart mode you can change it by pressing "Insert" key or
clicking on "Smart Insert" in the status field. You will then get the normal
I-caret and smartness will be gone i.e. no spaces will be inserted.
Comment 4 Alexander Veit CLA 2003-10-29 16:41:48 EST
... Now once again hit <return>.

What I would expect is

class A
{
   void f()
   {
       Object l_obj;
<no spacing>
       <caret at the correct indentation position>
   }
}

A less sophisticated solution for the problem would be to strip trailing 
whitespace from the end of each line when saving the source file.
Comment 5 Dani Megert CLA 2003-11-06 04:10:03 EST
The 80% case when typing in your last scenario is that you continue at the
indented location.

I support your last suggestion.

*** This bug has been marked as a duplicate of 25360 ***