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

Summary: hint "break outside of switch or loop" doesn't work for labeled breaks
Product: java Reporter: almson
Component: HintsAssignee: Svata Dedic <sdedic>
Status: NEW ---    
Severity: normal    
Priority: P3    
Version: 7.4   
Hardware: PC   
OS: Windows 8   
Issue Type: ENHANCEMENT Exception Reporter:

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.