Bug 534139 - Editor sometimes mistakes curly brace inside of string literal as a semantic curly brace
Summary: Editor sometimes mistakes curly brace inside of string literal as a semantic ...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.7.3   Edit
Hardware: PC Windows 10
: P3 normal with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2018-04-27 04:47 EDT by Lukas Eder CLA
Modified: 2023-09-01 15:45 EDT (History)
2 users (show)

See Also:


Attachments
Annimated Gif to demonstrate the problem (1.27 MB, image/gif)
2018-07-03 05:18 EDT, Jeremie Bresson CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lukas Eder CLA 2018-04-27 04:47:57 EDT
Consider this code:

// ---------------------------------------------
public class CurlyBrace {
    public static void m() {
        if ("".equals(""))
            x(" ");
        else
            x(" ");
        //     ^ place cursor here and type {
    }

    static void x(String s) {}
}
// ---------------------------------------------

Now, place the cursor inside of the second " " string literal and type an opening curly brace. The curly brace isn't placed inside of the string literal, but towards the end of the line instead:

// ---------------------------------------------
public class CurlyBrace {
    public static void m() {
        if ("".equals(""))
            x(" ");
        else
            x(" ") {;
        //     ^ place cursor here and type {
    }

    static void x(String s) {}
}
// ---------------------------------------------

Immediately typing backspace will fix this:


// ---------------------------------------------
public class CurlyBrace {
    public static void m() {
        if ("".equals(""))
            x(" ");
        else
            x(" {");
        //     ^ place cursor here and type {
    }

    static void x(String s) {}
}
// ---------------------------------------------

But that's a bit annoying. The "improvement" shouldn't be done in the first place.
Comment 1 Lukas Eder CLA 2018-04-27 07:38:04 EDT
The issue can actually be worked around by turning off the preference Java > Editor > Typing > Braces as was kindly pointed out to me by Nándor Előd Fekete on Twitter:
https://twitter.com/nandor_fekete/status/989823778594217984
Comment 2 Jeremie Bresson CLA 2018-07-03 05:18:41 EDT
Created attachment 274763 [details]
Annimated Gif to demonstrate the problem

Add an annimated gif to demonstrate a similar problem.

Tested in:

Eclipse IDE for Java Developers
Version: Photon Release (4.8.0)
Build id: 20180619-1200
Comment 3 Nathaniel Mishkin CLA 2019-09-20 17:36:16 EDT
FWIW I'd never seen this behavior but am now seeing it with 4.13.
Comment 4 Eclipse Genie CLA 2021-09-10 09:28:35 EDT
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 5 Eclipse Genie CLA 2023-09-01 15:45:54 EDT
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.