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

Comments

Projects
None yet
3 participants
@KroArtem

KroArtem commented Aug 30, 2018

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

This comment has been minimized.

Member

jsotuyod commented Aug 30, 2018

@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 this to the 6.7.0 milestone Aug 30, 2018

@jsotuyod jsotuyod changed the title from [java] AvoidUsingHardCodedIP reports unexpectedly to [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

@jsotuyod jsotuyod added the has:pr label Aug 30, 2018

@adangel

This comment has been minimized.

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

[java] AvoidUsingHardCodedIP false positive for ":bee"
"::bee" (two colons) is a valid IPv6 address, while ":bee"
is not.

Refs pmd#1323

@adangel adangel closed this in #1324 Sep 1, 2018

@KroArtem

This comment has been minimized.

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