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

Disallow URL in equals methods (or @Value.Immutable classes) #469

Open
iamdanfox opened this issue Nov 26, 2018 · 3 comments
Open

Disallow URL in equals methods (or @Value.Immutable classes) #469

iamdanfox opened this issue Nov 26, 2018 · 3 comments

Comments

@iamdanfox
Copy link
Contributor

What happened?

@jroitgrund and I just had a wild time with a debugger hooked up to a production service, where it seemed like an equals method was returning false when it should have been true!

@Value.Immutable
@ImmutablesStyle
@JsonSerialize(as = ImmutableDeploymentConfiguration.class)
@JsonDeserialize(as = ImmutableDeploymentConfiguration.class)
public interface DeploymentConfiguration {
	// ...
    @JsonProperty("public-url")
    URL publicUrl();

On the box, it seemed that the URL object constructed from the same string resulted in a DNS lookup which sometimes returned different IP addresses (because that service was deployed in multiple places).

this meant that occasionally, this would return false:

URL url1 = new URL("https://something.example.com");
// wait a bit because we tell Java to cache DNS for 20 seconds '-Dsun.net.inetaddr.ttl=20'
URL url2 = new URL("https://something.example.com");

url1.equals(url2); // 🌶🌶🌶 can return false! 

What did you want to happen?

We can't change the URL class itself, so I think we should write an errorprone check to prevent bugs like this.

We could ban comparisons of URL.equals URL and also @Value.Immutable fields which are URLs.

@carterkozak
Copy link
Contributor

We may want to bump this to ERROR by default to catch subtler instances of this failure: http://errorprone.info/bugpattern/URLEqualsHashCode

@iamdanfox
Copy link
Contributor Author

Closing out because promoting that to ERROR means it should catch stuff even inside generated immutables code!

@iamdanfox iamdanfox reopened this Nov 19, 2020
@iamdanfox
Copy link
Contributor Author

Re-opening because it seems like a dev team hit this exact case and error-prone didn't warn them :/

public interface KubernetesEnvironmentConfig {
    DockerConfig docker();

    SslConfiguration dispatcherSecurity();

    List<URL> ingressUris();  // <- 🌶🌶🌶

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants