Bug 575025

Summary: Code Completion overwrites too aggessively
Product: [Eclipse Project] JDT Reporter: Marvin Fröhlich <eclipse>
Component: TextAssignee: JDT-Text-Inbox <jdt-text-inbox>
Status: ASSIGNED --- QA Contact:
Severity: normal    
Priority: P3 CC: blueice_eclipse, ctg, joel.costigliola, noopur_gupta, twolf
Version: 4.20Keywords: needinfo
Target Milestone: ---   
Hardware: PC   
OS: Windows 10   
Whiteboard:
Attachments:
Description Flags
Test code none

Description Marvin Fröhlich CLA 2021-07-26 01:58:30 EDT
The latest (stable) Eclipse release introduced a bug in the code completion Overwrite scheme.

If I have this method definition and call code:

void setABC(String a, String b, String c);

setA|XYZ( "x", "y", "z" );

where the pipe represents the caret and I press CTRL+Space, followed by Enter to overwrite the old method call (preferences are configured to overwrite by default), previous versions only overwrote the method name up to the next separating character like the parenthesizes.

The new version also removes the complete signature and replaces it with default values in linked mode.

This may be desired behavior for someone. But for me it makes my beloved overwrite mode pretty useless.

Is this wanted behavior? If yes, would you mind, making this configurable?
Comment 1 Noopur Gupta CLA 2021-07-26 02:48:43 EDT
I don't see this issue with the latest Eclipse 4.21 I-build.

Please provide a complete code snippet to reproduce the issue. 

Also mention the Eclipse releases where it worked and where it stopped working for you. 

Please check that you don't have any additional plug-ins installed on the SDK causing this.
Comment 2 Marvin Fröhlich CLA 2021-08-06 02:32:29 EDT
My snippet above is more or less complete.

(Un)fortunately I don't see this behavior anymore without me changing anything.

I tried it with a fresh Eclipse for Java Developers anda virgin workspace. The issue didn't show up.

Now I don't even see it with my enriched installation.

I will report back when I next see it.
Comment 3 Marvin Fröhlich CLA 2021-08-06 02:36:43 EDT
Wenn, it could be the content assis advanced settings. They tend to go a little wild since the last release. I tried to optimize them to get rid of some duplications in the proposals list.

At least this is something I changed.

Would you expect this to cause issues like this?
Comment 4 Noopur Gupta CLA 2021-08-06 04:04:51 EDT
(In reply to Marvin  Fröhlich from comment #3)
> Wenn, it could be the content assis advanced settings. They tend to go a
> little wild since the last release. I tried to optimize them to get rid of
> some duplications in the proposals list.
> 
> At least this is something I changed.
> 
> Would you expect this to cause issues like this?
I don't think so. But if you can identify any setting causing this or the duplication issues with reproducible test case then please report back.
Comment 5 Marvin Fröhlich CLA 2021-09-27 08:30:28 EDT
Hey Noopur,

unfortunately I still cannot provide minimalistic test code to reproduce it. But I can definitely report this:

I can reproduce it consistently in certain sections of our domain code.
I can reproduce it with a fresh and unchanged 2021-09.
It is still reproducible after resetting Content Assist->Advanced settings to defaults.

Unfortunately it doesn't show up in my minimalistic test project. But hopefully this helps you in any way to find it.

I would at least want to let this ticket open, because the bug persists and is not fixed or invalid.

This behavior started from 2021-06, it worked in 2021-03 R. It persists in 2021-09 R.
Comment 6 Noopur Gupta CLA 2021-09-28 05:22:51 EDT
I will keep the bug open so that any other user who is facing this can add details to reproduce.

Also, check if you can reproduce it with the plain SDK: https://download.eclipse.org/eclipse/downloads/drops4/R-4.21-202109060500/

Or, if there are other plug-ins on top of the SDK that might be causing it.
Comment 7 Marvin Fröhlich CLA 2021-10-19 04:17:10 EDT
Created attachment 287342 [details]
Test code

Test code to reproduce aggressive overwrite
Comment 8 Marvin Fröhlich CLA 2021-10-19 04:21:45 EDT
Finally I managed to create test code to reproduce the behavior with code, that I can actually share. Please see the attached project. There's the class WebDocAuthenticatorProxy.

Navigate to line 51 and place the caret before the opening parenthesize. Hit Ctrl+Space followed by Enter.

Make sure to set preferences setting to overwrite instead of insert when auto completing.

Line before:
actualAuthenticator.setHeader( xyz );

Expected result:
actualAuthenticator.setHeaderUser( xyz );

Erraneous (current) result:
actualAuthenticator.setHeaderUser( headerUser );


Hope, this helps.
Comment 9 Thomas Wolf CLA 2021-10-22 10:23:55 EDT
Here's a super-simple example:

Start with this class:

public class Testing {

	public <T> T getAdapter(Class<T> adapter) {
		if (adapter == Testing.class) {
			return this;
		}
		return null;
	}

}

Place the cursor before the "t" in "return this;"

Type "adapter." You get content assist with adapter.cast() as the first completion suggestion, which is what we want. Accept that suggestion.

Result:

  return adapter.cast(adapter);

Thank you. That code even compiles. But crashes at run-time. See bug 576838 :-(
Comment 10 Joel Costigliola CLA 2022-03-14 06:15:14 EDT
I second Marvin, the new code completion overwrite behavior is sometimes different from what it used to be before.

In version Version: 2021-12 (4.22.0) / Build id: 20211202-1639, with the following settings:
- Completion overwrites: enabled
- Insert single proposal automatically: disabled
- Insert common prefixes automatically: disabled
- Disable insertion triggers except 'Enter': disabled
- Fill method arguments: disabled.

I can reproduce the behavior with a simple AssertJ assertion call, starting from:

  assertThat('a').isLessThan('b');

triggering code completion at | 

  assertThat('a').isE|LessThan('b');

select isEqualTo leads to:

a  ssertThat('a').isEqualTo()

instead of 

assertThat('a').isEqualTo('b');

which means rewriting the parameter and the semi-colon.
At this point, it's more efficient to not overwrite and remove the unwanted LessThan instead of loosing the parameters.

Surprisingly, code completion overwrites works as I expected in this example:

    String s = "foo";
    s.replaceAll(s);

code completion at re|placeAll and select replaceFirst works fine and gives 

   s.replaceFirst(s);

I'm not sure why the behavior is inconsistent but TBH let me say it's really irritating to the point of I'm considering switching IDEs.