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 253096 - Default constant name pattern gives strange warnings
Summary: Default constant name pattern gives strange warnings
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.1
Hardware: PC Other
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-21 13:50 UTC by cezariusz
Modified: 2015-07-29 01:29 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description cezariusz 2015-06-21 13:50:03 UTC
Product Version: NetBeans IDE Dev (Build 201506070001)
Java: 1.8.0_45; Java HotSpot(TM) 64-Bit Server VM 25.45-b02
Runtime: Java(TM) SE Runtime Environment 1.8.0_45-b15
System: Windows 8 version 6.2 running on amd64; UTF-8; pl_PL (nb)

The default pattern for constant naming convention is:
([A-Z][A-Z\d]+_?)*[A-Z\d]+

It gives warnings for constants like:
AM_I_RIGHT
ON_A_TABLE
VERSION_2_0
X_123

For some reason it doesn't allow a single letter or digit between underscores. Why the pattern isn't for example like this:
([A-Z\d]+_?)*[A-Z\d]+
Comment 1 Svata Dedic 2015-07-24 12:42:15 UTC
Better "([A-Z][A-Z\\d]*_?)*[A-Z\\d]+" -- should start with a letter.

Fixed in jet-main#ba63be1e0997
Comment 2 cezariusz 2015-07-24 12:55:27 UTC
Your pattern matches invalid identifiers, for example:
4DOS
And it doesn't match some valid ones, like:
VERSION_2_0
Comment 3 Svata Dedic 2015-07-24 19:40:14 UTC
OK, so what about :)
[A-Z]([A-Z\\d]*_)*[A-Z\\d]+

- starting with a letter
- followed by 0-n alphanum sequences with trailing _ separating words
- terminated by non-empty alphanum sequence.
Comment 4 cezariusz 2015-07-27 08:51:38 UTC
(In reply to Svata Dedic from comment #3)
> OK, so what about :)
> [A-Z]([A-Z\\d]*_)*[A-Z\\d]+

Way better, but it's worth noting that it doesn't allow single letter constants.
Comment 5 Quality Engineering 2015-07-29 01:29:52 UTC
Integrated into 'main-silver', will be available in build *201507290002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/ba63be1e0997
User: Svata Dedic <sdedic@netbeans.org>
Log: #253096, #252965: adjusted default pattern. Enabled only immutable checking by default.