Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] Fix AvoidUsingOctalValues false-positive #5020

Merged
merged 1 commit into from
May 21, 2024
Merged

Conversation

Gold856
Copy link
Contributor

@Gold856 Gold856 commented May 15, 2024

Describe the PR

ASTNumericLiteral did not correctly determine the base when a number ended with a non-number (L, F, D, .) This PR checks if the number ends with one of those characters, and correctly returns a base of 10.

Related issues

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

Copy link
Member

@jsotuyod jsotuyod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! We greatly appreciate the contribution.

I've added some comments to improve the code. We should also add a new test case for the AvoidUsingOctalValues rule. You can do so adding a new <test-code> node in AvoidUsingOctalValues.xml

@Gold856
Copy link
Contributor Author

Gold856 commented May 15, 2024

I added some test cases and fixed the logic; the code now checks for a period in the literal along with a float or double suffix at the end (after the hex and binary check), since those do cause the base to change to base 10.

@jsotuyod jsotuyod changed the title Fix AvoidUsingOctalValues false-positive [java] Fix AvoidUsingOctalValues false-positive May 15, 2024
@pmd-test
Copy link

pmd-test commented May 15, 2024

1 Message
📖 Compared to master:
This changeset changes 0 violations,
introduces 8 new violations, 0 new errors and 0 new configuration errors,
removes 2 violations, 0 errors and 0 configuration errors.
Download full report as build artifact
Compared to master:
This changeset changes 0 violations,
introduces 8 new violations, 0 new errors and 0 new configuration errors,
removes 2 violations, 0 errors and 0 configuration errors.
Download full report as build artifact
Compared to master:
This changeset changes 0 violations,
introduces 8 new violations, 0 new errors and 0 new configuration errors,
removes 2 violations, 0 errors and 0 configuration errors.
Download full report as build artifact
Compared to master:
This changeset changes 0 violations,
introduces 63 new violations, 0 new errors and 0 new configuration errors,
removes 2 violations, 0 errors and 0 configuration errors.
Download full report as build artifact

Generated by 🚫 Danger

@jsotuyod
Copy link
Member

Let's see what the regression tester shows, but it seems better.

I'd probably just add a test case before merging on the case 0x1.0000_ffff_eeeep+2f for the rule UseUnderscoresInNumericLiterals, as this was detected by the regression tester but not our own rules, so we are obviously missing this scenario there.

But other than that, if @pmd-test doesn't show anything weird, this is good to go.

@Gold856 Gold856 force-pushed the master branch 4 times, most recently from 9a5bdbc to e62e909 Compare May 16, 2024 02:55
@Gold856
Copy link
Contributor Author

Gold856 commented May 16, 2024

Added the float literal test case. Also added code to check for exponents (those can also change an octal to decimal) with a test case.

Copy link
Member

@jsotuyod jsotuyod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Thanks!

@oowekyala oowekyala added this to the 7.2.0 milestone May 21, 2024
@oowekyala
Copy link
Member

Thank you @Gold856!

oowekyala added a commit that referenced this pull request May 21, 2024
oowekyala added a commit that referenced this pull request May 21, 2024
@oowekyala oowekyala merged commit e11376f into pmd:master May 21, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[java] AvoidUsingOctalValues triggers on non-octal double literals with a leading 0
4 participants