diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 60a0d9953..c843b878e 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -36,7 +36,8 @@ No features have been promoted in this picocli release. - [#325] Enhancement: Allow custom type converter to map empty String to custom default value for empty options. Thanks to [jesselong](https://github.com/jesselong) for the suggestion. - [#303] Enhancement: Improve validation to prevent common mistakes. - [#327] Bugfix: Default values should not cause options and positional parameters to be added to ParseResult. -- [#330] Bugfix: Interpreter should clear option's and positional parameter's rawStringValues list before parsing new input. +- [#330] Bugfix: `Interpreter` should clear option's and positional parameter's rawStringValues list before parsing new input. +- [#335] Bugfix: Abstract class `ArgSpec` should not implement `equals` and `hashCode`. ## Deprecations See [3.0.0-alpha-1](https://github.com/remkop/picocli/releases/tag/v3.0.0-alpha-1#3.0.0-alpha-1-deprecated) diff --git a/src/main/java/picocli/CommandLine.java b/src/main/java/picocli/CommandLine.java index 606f73b7b..ce8e8fcc0 100644 --- a/src/main/java/picocli/CommandLine.java +++ b/src/main/java/picocli/CommandLine.java @@ -3524,10 +3524,8 @@ protected boolean showDefaultValue(CommandSpec commandSpec) { private String[] splitValue(String value) { return splitRegex().length() == 0 ? new String[] {value} : value.split(splitRegex()); } - public boolean equals(Object obj) { - if (obj == this) { return true; } - if (!(obj instanceof ArgSpec)) { return false; } - ArgSpec other = (ArgSpec) obj; + protected boolean equalsImpl(ArgSpec other) { + if (other == this) { return true; } boolean result = Assert.equals(this.defaultValue, other.defaultValue) && Assert.equals(this.type, other.type) && Assert.equals(this.arity, other.arity) @@ -3540,7 +3538,7 @@ public boolean equals(Object obj) { ; return result; } - public int hashCode() { + protected int hashCodeImpl() { return 17 + 37 * Assert.hashCode(defaultValue) + 37 * Assert.hashCode(type) @@ -3796,7 +3794,7 @@ public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof OptionSpec)) { return false; } OptionSpec other = (OptionSpec) obj; - boolean result = super.equals(obj) + boolean result = super.equalsImpl(other) && help == other.help && usageHelp == other.usageHelp && versionHelp == other.versionHelp @@ -3804,7 +3802,7 @@ public boolean equals(Object obj) { return result; } public int hashCode() { - return super.hashCode() + return super.hashCodeImpl() + 37 * Assert.hashCode(help) + 37 * Assert.hashCode(usageHelp) + 37 * Assert.hashCode(versionHelp) @@ -3931,7 +3929,7 @@ private PositionalParamSpec(Builder builder) { public static Builder builder() { return new Builder(); } public int hashCode() { - return super.hashCode() + return super.hashCodeImpl() + 37 * Assert.hashCode(capacity) + 37 * Assert.hashCode(index); } @@ -3943,7 +3941,8 @@ public boolean equals(Object obj) { return false; } PositionalParamSpec other = (PositionalParamSpec) obj; - return Assert.equals(this.capacity, other.capacity) + return super.equalsImpl(other) + && Assert.equals(this.capacity, other.capacity) && Assert.equals(this.index, other.index); }