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] AvoidUsingHardCodedIP ignores match pattern #1323

Closed
KroArtem opened this issue Aug 30, 2018 · 3 comments
Closed

[java] AvoidUsingHardCodedIP ignores match pattern #1323

KroArtem opened this issue Aug 30, 2018 · 3 comments
Labels
a:bug PMD crashes or fails to analyse a file. in:documentation Affects the documentation
Milestone

Comments

@KroArtem
Copy link
Contributor

Affects PMD Version:
6.5.0
Rule:
AvoidUsingHardCodedIP
Description:
AvoidUsingHardCodedIP reports that string ":bee" is a hardcoded IP. It looks like support for IPv6 was added but documentation is outdated.

Code Sample demonstrating the issue:

taskViewSteps.printComment(":bee")

Leads to PMD reporting the following:

Application with hard-coded IP addresses can become impossible to deploy in some cases.
Externalizing IP adresses is preferable.AvoidUsingHardCodedIP

Running PMD through: Junit test runs pmd

Docs say pattern is ^"[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}"$

@jsotuyod
Copy link
Member

@KroArtem thanks for spotting this one!

That property is actually unused, and should be removed. It's legacy from back when the rule was a pure XPath rule:

<properties>
<property name="pattern" type="String" description="Regular Expression" value='^"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"$'/>
</properties>

The one property that is actually honoured is the checkAddressTypes as documented on https://pmd.github.io/pmd-6.6.0/pmd_rules_java_bestpractices.html#avoidusinghardcodedip

That property defaults to checking all, IPv4, IPv6 and IPv4 mapped IPv6.

@jsotuyod jsotuyod added a:bug PMD crashes or fails to analyse a file. in:documentation Affects the documentation labels Aug 30, 2018
@jsotuyod jsotuyod added this to the 6.7.0 milestone Aug 30, 2018
@jsotuyod jsotuyod changed the title [java] AvoidUsingHardCodedIP reports unexpectedly [java] AvoidUsingHardCodedIP ignores match pattern Aug 30, 2018
jsotuyod added a commit to Monits/pmd that referenced this issue Aug 30, 2018
jsotuyod added a commit to Monits/pmd that referenced this issue Aug 30, 2018
@adangel
Copy link
Member

adangel commented Sep 1, 2018

":bee" is indeed a invalid ipv6 address, a valid one would be "::bee".

adangel added a commit to adangel/pmd that referenced this issue Sep 1, 2018
"::bee" (two colons) is a valid IPv6 address, while ":bee"
is not.

Refs pmd#1323
@KroArtem
Copy link
Contributor Author

KroArtem commented Sep 3, 2018

Thanks a lot for explanation, updated pmd to 6.7.0, seems to be working ok now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug PMD crashes or fails to analyse a file. in:documentation Affects the documentation
Projects
None yet
Development

No branches or pull requests

3 participants