Bug 385435 - [breakpoints] Can't set breakpoint in line with local variable declaration (error message "Selection does not contain a field")
Summary: [breakpoints] Can't set breakpoint in line with local variable declaration (e...
Status: REOPENED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 3.6.2   Edit
Hardware: All All
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Sarika Sinha CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
: 333600 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-07-18 15:45 EDT by Joshua Goldberg CLA
Modified: 2024-01-12 00:22 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joshua Goldberg CLA 2012-07-18 15:45:13 EDT
Eclipse beeps and gives the message "Selection does not contain a field" if you try to add a breakpoint on a line with a variable declaration.  The message could be made much clearer.


-- Configuration Details --
Product: Eclipse 1.3.2.20110218-0812 (org.eclipse.epp.package.java.product)
Installed Features:
 org.eclipse.jdt 3.6.2.r362_v20101117-0800-7z8XFW6FLFlmjJcvz03jyeFBLS_F
Comment 1 Joshua Goldberg CLA 2012-07-18 15:46:37 EDT
I mean a line like:  int x;
Comment 2 Michael Rennie CLA 2012-07-23 10:27:13 EDT
You only get that vague error when we fail to resolve the field you are trying to set the watchpoint on in the backing AST. Joshua can you attach the snippet that causes the exception to be shown?

I suppose at the very minimum we could include the text of the selection in the error message - something like "'String foo' does not contain a valid field name"
Comment 3 Joshua Goldberg CLA 2012-07-23 14:43:50 EDT
Any local variable definition seems to give the message.

Part of the problem is that I was trying to set a breakpoint, not a watchpoint.  (I'd simply maant to break "around here" in a method, not thinking about whether the line was declaration vs. statement.)

Now that you've put the watchpoint/breakpoint distinction in my head, I think I have a solution: the message should say (assuming this is always true in eclipse) "Watchpoints cannot be set on local variables."

(I don't think adding the '"String foo" does not contain' would have helped me by the way.)
Comment 4 Michael Rennie CLA 2012-07-23 15:22:58 EDT
(In reply to comment #3)
> Any local variable definition seems to give the message.
> 
> Part of the problem is that I was trying to set a breakpoint, not a watchpoint.
>  (I'd simply maant to break "around here" in a method, not thinking about
> whether the line was declaration vs. statement.)
> 

How are you trying to set the breakpoint? No matter how I try to set a breakpoint on fields (local or otherwise / line bp or watchpoint) it works as expected - I do not see the message.

> Now that you've put the watchpoint/breakpoint distinction in my head, I think I
> have a solution: the message should say (assuming this is always true in
> eclipse) "Watchpoints cannot be set on local variables."

Would it be possible for you to run your test case on a newer version of Eclipse (3.8/4.2)? We have made a few changes since 3.6 to how we toggle breakpoints.
Comment 5 Joshua Goldberg CLA 2012-07-23 15:26:36 EDT
I see it whether I double-click the sidebar or use the Shift-Cmd-B keyboard shortcut.

It may be some time before I'm able to upgrade to a newer eclipse I'm afraid.  I'll see what I can do.
Comment 6 Michael Rennie CLA 2012-07-24 10:13:17 EDT
(In reply to comment #5)
> I see it whether I double-click the sidebar or use the Shift-Cmd-B keyboard
> shortcut.
> 
> It may be some time before I'm able to upgrade to a newer eclipse I'm afraid. 
> I'll see what I can do.

In the meantime then, since we both agree an update to the message will not be sufficient and I cannot reproduce, I will close as WORKSFORME and we can reopen once you get a chance to test a newer version of Eclipse (if needed).
Comment 7 Joshua Goldberg CLA 2012-07-24 10:15:35 EDT
That's fine.
Comment 8 Markus Keller CLA 2015-12-06 16:42:45 EST
When I double-click the annotation ruler or use Run > Toggle Breakpoint on a line that just declares a local variable, the breakpoint is not accepted. However, when I try to do the same on a line before, then it works (toggles the line breakpoint on the next applicable line).

Snippet:

    void foo() {
        System.out.println(1);
// can toggle breakpoint on these empty lines => jumps to "index = 2"

        int index; // cannot set a breakpoint
        index = 2;
        System.out.println(index);
    }

If you use the command or double-click in the vertical ruler, you can see an error message in the status bar, saying "Selection does not contain a field". (Caveat: If you double-click the line number/change ruler, the message quickly disappears. That's bug 483747).

The message "Selection does not contain a field" doesn't make sense and should not be generated for local variable without an initializer. Toggling a breakpoint on that line should work the same as on the empty lines before. I guess the problem is that the local variable declaration is wrongly considered to be a field declaration.
Comment 9 Markus Keller CLA 2015-12-06 16:43:26 EST
*** Bug 333600 has been marked as a duplicate of this bug. ***
Comment 10 Sarika Sinha CLA 2015-12-06 22:58:30 EST
Thanks Markus, I am able reproduce it with the attached snippet.
Comment 11 Ciro Santilli CLA 2017-08-19 14:18:17 EDT
The current error message is:

> This operation is unavailable on the current selection. Please select or place the cursor on a field.

Test code:

int global = 0;

int main() {
    int local = 0;
    local = 1;
    global = 1;
}

To reproduce, select the declaration of "local", and do "Run -> Toggle watchpoint".

See also: https://stackoverflow.com/questions/45774814/how-to-create-a-watchpoint-for-a-local-variable-in-eclipse-cdt
Comment 12 Eclipse Genie CLA 2020-01-31 03:26:32 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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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 13 Sarika Sinha CLA 2020-01-31 03:33:46 EST
Still an issue.
Comment 14 Eclipse Genie CLA 2022-01-21 03:02:17 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 15 Eclipse Genie CLA 2024-01-12 00:22:16 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.