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

Bug 520081

Summary: [typing] Automatically insert brace at correct position moves { entered in empty string to end of line
Product: [Eclipse Project] JDT Reporter: Rasa Mišeikytė <rasa.miseikyte>
Component: TextAssignee: Julian Honnen <julian.honnen>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: anma-e, basinilya, daniel_megert, julian.honnen, laville, mauromol, noopur_gupta, p.rader, restful.koala, rgrunber, sewe, stephan.herrmann
Version: 4.8   
Target Milestone: 4.16 M1   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/159048
https://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=8ac6881d75ce9eb05ca2c5dd8a38f18fece5c75a
https://bugs.eclipse.org/bugs/show_bug.cgi?id=546931
Whiteboard:
Attachments:
Description Flags
error happens when trying to enter { at line 110 (to pass "{" as third term of new StringJoiner(...)) none

Description Rasa Mišeikytė CLA 2017-07-24 03:44:13 EDT
Created attachment 269503 [details]
error happens when trying to enter { at line 110 (to pass "{" as third term of new StringJoiner(...))

Oxygen: Java code editor: Impossible to enter { within empty string "" - every time Eclipse creates this { at the end of the line: only way I managed to create string "{" was when keeping it the only items in line (moving rest of code down).

Example code attached: error happens when trying to enter { at line 110 (to pass "{" as third term of new StringJoiner(...))


Looking forward for fix!!!


-- Configuration Details --
Product: Eclipse 4.7.0.20170620-1800 (org.eclipse.epp.package.java.product)Installed Features:
 org.eclipse.jdt 3.13.0.v20170612-0950
Comment 1 Noopur Gupta CLA 2017-07-25 07:51:19 EDT
It happens when "Preferences > Java > Editor > Typing > Automatically insert at correct position > Braces" is checked. As a workaround for now, you can disable this option.
Comment 2 Dani Megert CLA 2017-11-21 12:25:31 EST
*** Bug 527552 has been marked as a duplicate of this bug. ***
Comment 3 Dani Megert CLA 2017-11-21 12:27:09 EST
(In reply to Noopur Gupta from comment #1)
> As a workaround for now, you can disable this option.

You can simply press 'Delete' to move the '{' to the expected position. That trick works with almost all smart typing options.
Comment 4 Noopur Gupta CLA 2017-11-22 07:29:05 EST
(In reply to Dani Megert from comment #3)
> (In reply to Noopur Gupta from comment #1)
> > As a workaround for now, you can disable this option.
> 
> You can simply press 'Delete' to move the '{' to the expected position. That
> trick works with almost all smart typing options.

I tried 'Delete' but it didn't work. Did you mean the 'Backspace' key instead? 'Backspace' works and brings back the '{' to the correct position. Nice trick!
Comment 5 Dani Megert CLA 2017-11-22 08:27:54 EST
(In reply to Noopur Gupta from comment #4)
> (In reply to Dani Megert from comment #3)
> > (In reply to Noopur Gupta from comment #1)
> > > As a workaround for now, you can disable this option.
> > 
> > You can simply press 'Delete' to move the '{' to the expected position. That
> > trick works with almost all smart typing options.
> 
> I tried 'Delete' but it didn't work. Did you mean the 'Backspace' key
> instead? 'Backspace' works and brings back the '{' to the correct position.
> Nice trick!

Yes, 'Backspace'.
Comment 6 Noopur Gupta CLA 2017-12-07 06:01:29 EST
*** Bug 527997 has been marked as a duplicate of this bug. ***
Comment 7 Stephan Herrmann CLA 2018-11-06 05:26:39 EST
*** Bug 540819 has been marked as a duplicate of this bug. ***
Comment 8 Mauro Molinari CLA 2018-11-06 05:38:29 EST
Please note that the workaround to hit backspace works only if you press it IMMEDIATELY after the "{". If you meanwhile have typed something else (quite common), hitting backspace repeatedly won't cancel the effect of this undesired insertion.
Comment 9 Mauro Molinari CLA 2018-11-06 05:40:13 EST
I would also raise the importance to "normal" at least, since the current behaviour is quite frustrating (see my report in bug #540819 - sorry for the duplicate).
Comment 10 Stephan Herrmann CLA 2018-11-11 12:45:58 EST
*** Bug 541002 has been marked as a duplicate of this bug. ***
Comment 11 Stephan Herrmann CLA 2018-11-11 12:46:33 EST
(In reply to Stephan Herrmann from comment #10)
> *** Bug 541002 has been marked as a duplicate of this bug. ***

This one contains an even trickier example.
Comment 12 Stephan Herrmann CLA 2019-09-21 16:24:22 EDT
I just had to search this bug again to find the workaround, after being unable to insert '{' into a string literal.
I can confirm, even after having heard about the workaround, 10 months later I was completely clueless how to teach Eclipse the basics of text editing. This is not a minor problem.
Comment 13 Eclipse Genie CLA 2020-03-09 10:54:05 EDT
New Gerrit change created: https://git.eclipse.org/r/159048
Comment 15 Julian Honnen CLA 2020-04-07 03:13:36 EDT
verified on 
Version: 2020-06 (4.16)
Build id: I20200406-0600