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

[BUG] Arrays annotations and EqualsAndHashCode #2166

Closed
sanyarnd opened this issue Jul 1, 2019 · 1 comment
Closed

[BUG] Arrays annotations and EqualsAndHashCode #2166

sanyarnd opened this issue Jul 1, 2019 · 1 comment

Comments

@sanyarnd
Copy link

sanyarnd commented Jul 1, 2019

Describe the bug
Lombok does not produce deepEquals comparison for arrays if array type (private Byte @NonNull[] signature;) contains annotation:

@Value
@ToString(exclude = "signature")
public static final class Url {
	@NonNull
	private URL url;

	@NonNull
	private Byte @NonNull[] signature;
}

Bytecode output:

public static final class Url {
	@NonNull
	private final URL url;
	@NonNull
	private final Byte[] signature;

	@ConstructorProperties({"url", "signature"})
	public Url(@NonNull URL url, Byte[] signature) {
		if (url == null) {
			throw new NullPointerException("url is marked non-null but is null");
		} else if (signature == null) {
			throw new NullPointerException("signature is marked non-null but is null");
		} else {
			this.url = url;
			this.signature = signature;
		}
	}

	@NonNull
	public URL getUrl() {
		return this.url;
	}

	public Byte[] getSignature() {
		return this.signature;
	}

	public boolean equals(Object o) {
		if (o == this) {
			return true;
		} else if (!(o instanceof Version.Url)) {
			return false;
		} else {
			Version.Url other = (Version.Url)o;
			Object this$url = this.getUrl();
			Object other$url = other.getUrl();
			if (this$url == null) {
				if (other$url != null) {
					return false;
				}
			} else if (!this$url.equals(other$url)) {
				return false;
			}

			Object this$signature = this.getSignature();
			Object other$signature = other.getSignature();
			if (this$signature == null) {
				if (other$signature != null) {
					return false;
				}
			} else if (!this$signature.equals(other$signature)) {
				return false;
			}

			return true;
		}
	}

	public int hashCode() {
		int PRIME = true;
		int result = 1;
		Object $url = this.getUrl();
		int result = result * 59 + ($url == null ? 43 : $url.hashCode());
		Object $signature = this.getSignature();
		result = result * 59 + ($signature == null ? 43 : $signature.hashCode());
		return result;
	}

	public String toString() {
		return "Version.Url(url=" + this.getUrl() + ")";
	}
}

Expected behavior
I expected Arrays.deepEquals call as mentioned in documentation:

Arrays are 'deep' compared/hashCoded, which means that arrays that contain themselves will result in StackOverflowErrors. However, this behaviour is no different from e.g. ArrayList.

Version info (please complete the following information):

  • lombok version: 1.18.8
  • Platform: Oracle JDK 1.8.0_202
@sanyarnd sanyarnd changed the title [BUG] Arrays and EqualsAndHashCode [BUG] Arrays annotations and EqualsAndHashCode Jul 1, 2019
@sanyarnd
Copy link
Author

sanyarnd commented Jul 1, 2019

Duplicate of #2165 , github search didn't find any related issues.

@sanyarnd sanyarnd closed this as completed Jul 1, 2019
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