This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 234531 - hint "break outside of switch or loop" doesn't work for labeled breaks
Summary: hint "break outside of switch or loop" doesn't work for labeled breaks
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.4
Hardware: PC Windows 8
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-17 11:51 UTC by almson
Modified: 2013-09-02 14:20 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description almson 2013-08-17 11:51:47 UTC
The following statement generates a red hint:

{
    break;
}

However, the following does not:

label: {
    break label;
}

nor:

retry: try 
{
    throw new Exception();
}
catch(Exception e)
{
    break retry;
}

The compiler doesn't complain either, but Netbeans should inform that this code won't work as one might think.

Ideally, a hint should exist that also detects:
while(true)
{
    label: if(true)
    {
        break label;
    }
}
But the current "break outside of switch or loop" should at least detect the former situations.
Comment 1 Jan Lahoda 2013-08-18 18:03:55 UTC
To my surprise, breaking to a non-loop/switch label is perfectly valid as per the Java Language Specification (JLS 14.15). So not showing a compile-time error is absolutely correct.

Showing a warning might be reasonable (mostly because such break can be considered to be a code smell), but does not qualify as a defect, IMO.
Comment 2 almson 2013-08-19 09:53:58 UTC
Oh I see. It does work. It's a very limited form of goto.

I don't think a warning is necessary for this (I'm not one of those goto zealots). Your call.