Reputation: 337
I'm using PMD to check java code, and I've run into the problem that states, "Do not hard code IPv4 or IPv6 addresses, even 127.0.0.1!" The IPv4 address I'm using is in fact just 127.0.0.1, and is only for testing purposes, but nonetheless I must convert the hard-coded version to some sort of encrypted version. I'm not sure what would be the easiest way to do this.
Any help would be greatly appreciated!
Upvotes: 0
Views: 1534
Reputation: 21
I've resolved this PMD´s warning in this way:
// Old code
`if (!"127.0.0.1".equals(serverIP)) { ... }`
// New code
`if (!InetAddress.getLoopbackAddress().getHostAddress().equals(serverIP)) { ... }`
Upvotes: 2
Reputation: 2404
You are not trying to encrypt anything.
What you wan to do is pass in a host name and do the proper host lookup to get the Internet address. Look at the standard JDK's InetAddress and the getAllByName(String host) and getByName(String host)
Upvotes: 3