-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONARJAVA-4327 Improve rule description, add Java exception (#1533)
- Loading branch information
1 parent
d0ea589
commit ff343a5
Showing
6 changed files
with
39 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
== Compliant Solution | ||
|
||
[source,text] | ||
---- | ||
int thousand = 1000; | ||
int tenThousand = 10_000; | ||
int tenThousandWithout = 10000; | ||
int duos = 1_00_00; | ||
int million = 100_000_000; | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
== Exceptions | ||
|
||
No issue will be raised on binary numbers (starting with `0b` or `0B`). Binary number bits are often grouped corresponding to certain meanings, resulting in irregular bit group sizes. | ||
|
||
[source,java] | ||
---- | ||
int configValue1 = 0b00_000_10_1; // Compliant | ||
int configValue2 = 0B00_000_10_1; // Compliant | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
== Noncompliant Code Example | ||
|
||
[source,text] | ||
---- | ||
int thousand = 100_0 | ||
int tenThousand = 100_00; | ||
int million = 1_000_00_000; | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,4 @@ | ||
The use of punctuation characters to separate subgroups in a number can make the number more readable. For instance consider 1,000,000,000 versus 1000000000. But when the grouping is irregular, such as 1,000,00,000; it indicates an error. | ||
The use of punctuation characters to separate subgroups in a number can make the number more readable. For instance consider 1,000,000,000 versus 1000000000. But when the grouping is irregular, such as 1,000,00,000; it indicates an error. | ||
|
||
|
||
This rule raises an issue when underscores (``++_++``) are used to break a number into irregular subgroups. | ||
|
||
|
||
== Noncompliant Code Example | ||
|
||
[source,text] | ||
---- | ||
int duos = 1_00_00; | ||
int million = 1_000_00_000; // Noncompliant | ||
int thousand = 1000; | ||
int tenThousand = 100_00; // Noncompliant | ||
---- | ||
|
||
|