Skip to content

Commit

Permalink
Fix AvoidUsingOctalValue false-positive
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold856 committed May 16, 2024
1 parent feddca0 commit 9a5bdbc
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,19 @@ static int getBase(Chars image) {
case 'b':
case 'B':
return 2;
case '.':
return 10;
default:
return 8;
if (image.indexOf('.') != -1 || image.indexOf('e') != -1 || image.indexOf('E') != -1) {
return 10;
}
switch (image.charAt(image.length() - 1)) {
case 'f':
case 'F':
case 'd':
case 'D':
return 10;
default:
return 8;
}
}
}
return 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ public class Foo {
]]></code>
</test-code>

<test-code>
<description>ok, float literal in hexadecimal with decimal and exponent</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
float f = 0x1.0000_ffff_eeeep+2f;
}
]]></code>
</test-code>

<test-code>
<description>ok, Lengthy numeric literal with variable name as serialVersionUID</description>
<expected-problems>0</expected-problems>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,48 @@ public class Foo {
]]></code>
</test-code>

<test-code>
<description>OK, double value</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
double d = 012.0;
}
]]></code>
</test-code>

<test-code>
<description>OK, double suffix</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
double d1 = 012d;
double d2 = 012D;
}
]]></code>
</test-code>

<test-code>
<description>OK, float suffix</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
float f = 012f;
float f = 012F;
}
]]></code>
</test-code>

<test-code>
<description>OK, double value with exponent</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
double d = 012e0;
}
]]></code>
</test-code>

<test-code>
<description>bad, 012L</description>
<expected-problems>1</expected-problems>
Expand Down

0 comments on commit 9a5bdbc

Please sign in to comment.