org.sonar.l10n.java.rules.squid.S2112.html Maven / Gradle / Ivy
The newest version!
The equals
and hashCode
methods of java.net.URL
both make calls out to the Internet and are blocking operations. URI
on the other hand makes no such calls and should be used instead unless the specific URL
functionality is required.
This rule checks for uses of URL
's in Map
and Set
, and for explicit calls to the equals
and hashCode
methods.
Noncompliant Code Example
public void checkUrl(URL url) {
Set<URL> sites = new HashSet<URL>(); // Noncompliant
URL homepage = new URL("http://sonarsource.com"); // Compliant
if (homepage.equals(url)) { // Noncompliant
// ...
}
}
Compliant Solution
public void checkUrl(URL url) {
Set<URI> sites = new HashSet<URI>(); // Compliant
URI homepage = new URI("http://sonarsource.com"); // Compliant
URI uri = url.toURI();
if (homepage.equals(uri)) { // Compliant
// ...
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy