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

Avoid using HashSet with java.net.URL - causing significant slowdown #441

Open
czpilar opened this issue Nov 18, 2022 · 0 comments
Open

Comments

@czpilar
Copy link

czpilar commented Nov 18, 2022

ConfigurationBuilder class uses HashSet with java.net.URL which causes significant application slowdown.

public ConfigurationBuilder setUrls(Collection<URL> urls) {
		this.urls = new HashSet<>(urls);
        return this;
}

According to https://rules.sonarsource.com/java/RSPEC-2112

The equals and hashCode methods of java.net.URL both may trigger a name service (usually DNS) lookup to resolve the host name or IP address. Depending on the configuration, and network status, that can take a long time. URI on the other hand makes no such calls and should be used instead unless the specific URL functionality is required.

In general it is better to use the URI class until access to the resource is actually needed, at which point you can just convert the URI to a URL using URI.toURL().

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

No branches or pull requests

1 participant