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 212748

Summary: Adding warnings for misuse of the new literal underscores for primitive values
Product: java Reporter: gliesian <gliesian>
Component: HintsAssignee: Svata Dedic <sdedic>
Status: NEW ---    
Severity: normal    
Priority: P3    
Version: 7.1.2   
Hardware: PC   
OS: Windows 7   
Issue Type: ENHANCEMENT Exception Reporter:

Description gliesian 2012-05-20 11:13:45 UTC
Java 7 allows for underscored in literals (Reference - http://radar.oreilly.com/2011/09/java7-features.html).

For example, 

int value = 1000; 

could be written as

int value = 1_000;

The issue is, if it's written as

int value = 1_00_0;

it equates to 1000, but the IDE doesn't tell the user of possible mistake.

Yes, 1_00_0 isn't going to happen... but this may:

1_000_000_000_00_000_000;

Notice the missing zero... and yes, this is what the underscores is supposed to help with.  

My recommendation is to have a warning glyph shown in the gutter to the left, when a 0 is missing between underscores, as I believe that there is no reason to have a set of two (and not three) digits between underscores.

Thanks for the consideration, Robert
Comment 1 gliesian 2012-05-21 22:30:14 UTC
I may have made a mistake opening this...

You may want to use the underscores for other reasons, such as credit cards...

e.g., long creditCardNumber = 5555_5555_5555_5555;

However, if you thing about it, a credit should probably be a string.

This issue requires some thought before correcting.
Comment 2 gliesian 2012-05-21 22:44:11 UTC
Here's another example that goes against my reasoning: 

int socialSecurityID = 111_11_1111;
Comment 3 Jan Lahoda 2012-05-22 12:22:08 UTC
So far, there is only "Add Underscores" (Tools/Options/Editor/Hints/Language=Java/JDK 5 and later/Add Underscores) - disabled by default. But that pushes the same format to all literals, even those that do not have any underscores. It might be reasonable to add a warning in the future, that would only check consistency for literals which actually use underscores.