Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 94495 - [typing] Curly braces in string passed to argument in a constructor confuses editor
Summary: [typing] Curly braces in string passed to argument in a constructor confuses ...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.1   Edit
Hardware: All All
: P3 minor with 2 votes (vote)
Target Milestone: 4.23 M3   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact: Jeff Johnston CLA
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-10 15:50 EDT by Javier Kohen CLA
Modified: 2022-03-07 15:03 EST (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Javier Kohen CLA 2005-05-10 15:50:11 EDT
If I open a curly brace inside a string which is in turn inside the argument
list of a constructor, the curly brace appears outside the constructor, as if I
were trying to anonymously subclass the class to which the constructor belongs.

E.g. (^ is the caret):
1) new String(^)
2) new String("^")
3) Here I open curly braces:
3.a) What happens: new String("") {^
3.b) What I expect: new String("{^")

I'm using 3.1M6.
Comment 1 Tom Hofmann CLA 2005-05-11 04:11:44 EDT
Smart semicolon and smart opening brace also work from the inside of String
string literals. 

- while this is generally what you want for semicolons, the brace can be discussed
- typing backspace once gives you what you expected without smartness
- can be turned off on the Java>Editor>Typing preference page.
- it would be too expensive to detect whether the class being references is
subclassable (for example String).
Comment 2 Fabio Zadrozny CLA 2017-06-22 14:47:47 EDT
Note that this doesn't appear only in string constructors, but in any constructor.
Comment 3 Arne Deutsch CLA 2017-08-17 02:32:26 EDT
I think this is duplicated with following bugs:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=488244
https://bugs.eclipse.org/bugs/show_bug.cgi?id=520081

Probably the default for the preference has changed with Oxygen? In that case I would say the bug is quite severe right now.
Comment 4 Arne Deutsch CLA 2017-08-17 02:41:26 EDT
Regarding the comments from above ... I think that the smart insertion should be working only outside of string literals. Inside string literals you just want to type. If you, for example, try to encode a little code snippet inside a string and the cursor starts jumping outside the string, then this is clearly not expected behaviour.
Comment 5 Giovanni Lovato CLA 2018-08-09 06:29:04 EDT
I'm experiencing this too, not only constructors but also lambda: when I type '{' the brace and the cursors jump to the end on the line. I need to open the file on a different editor to type that brace.

How can I disable this behavior?
Comment 6 Jonathan Newbrough CLA 2018-10-19 15:48:36 EDT
workaround for v4.9: 

Open: Preferences
Navigate to page: Java->Editor->Typing
Uncheck "braces" under "Automatically insert at correct position"
Comment 7 Eclipse Genie CLA 2021-12-25 16:26:43 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 8 Dirk Steinkamp CLA 2022-03-04 18:18:35 EST
Seems to be fixed in the meantime. Not reproducible with 4.23M3
Comment 9 Jeff Johnston CLA 2022-03-07 15:03:22 EST
Yes, it does not occur in latest 4.23 even with automatically insert at correct position is selected for braces.  Will mark this as resolved.