From af6969a29a407f7765c97f05e8b64a69db217d6e Mon Sep 17 00:00:00 2001 From: Mateusz Stefanski Date: Sun, 23 Aug 2020 20:54:35 +0200 Subject: [PATCH 1/4] [doc] [java] SuspiciousEqualsMethodName: update description, fixes #2264 --- pmd-java/src/main/resources/category/java/errorprone.xml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pmd-java/src/main/resources/category/java/errorprone.xml b/pmd-java/src/main/resources/category/java/errorprone.xml index 65979fcc61..e2983797e7 100644 --- a/pmd-java/src/main/resources/category/java/errorprone.xml +++ b/pmd-java/src/main/resources/category/java/errorprone.xml @@ -3052,8 +3052,12 @@ StringBuilder sb4 = new StringBuilder("c"); class="net.sourceforge.pmd.lang.rule.XPathRule" externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#suspiciousequalsmethodname"> -The method name and parameter number are suspiciously close to equals(Object), which can denote an -intention to override the equals(Object) method. +The method name and parameter number are suspiciously close to Object.equals, which can denote an +intention to override it. However, the method does not override Object.equals, but overloads it instead. +Overloading Object.equals method is confusing for other programmers, error-prone and hard to main, +especially when using inheritance, because @Override annotations used in subclasses can provide a false +sense of security. For more information on Object.equals method, see Effective Java, 3rd Edition, +Item 10: Obey the general contract when overriding equals. 2 From 0a18460234c307f28fac06cac5d513eca0c5833d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Tue, 25 Aug 2020 14:37:29 +0200 Subject: [PATCH 2/4] Update pmd-java/src/main/resources/category/java/errorprone.xml --- pmd-java/src/main/resources/category/java/errorprone.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pmd-java/src/main/resources/category/java/errorprone.xml b/pmd-java/src/main/resources/category/java/errorprone.xml index e2983797e7..bdc9cc92c7 100644 --- a/pmd-java/src/main/resources/category/java/errorprone.xml +++ b/pmd-java/src/main/resources/category/java/errorprone.xml @@ -3054,7 +3054,7 @@ StringBuilder sb4 = new StringBuilder("c"); The method name and parameter number are suspiciously close to Object.equals, which can denote an intention to override it. However, the method does not override Object.equals, but overloads it instead. -Overloading Object.equals method is confusing for other programmers, error-prone and hard to main, +Overloading Object.equals method is confusing for other programmers, error-prone and hard to maintain, especially when using inheritance, because @Override annotations used in subclasses can provide a false sense of security. For more information on Object.equals method, see Effective Java, 3rd Edition, Item 10: Obey the general contract when overriding equals. From 36c3d872721954aae60df42d484624d3805bfb18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Tue, 25 Aug 2020 14:38:59 +0200 Subject: [PATCH 3/4] Add md formatting --- .../src/main/resources/category/java/errorprone.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pmd-java/src/main/resources/category/java/errorprone.xml b/pmd-java/src/main/resources/category/java/errorprone.xml index bdc9cc92c7..94875fb765 100644 --- a/pmd-java/src/main/resources/category/java/errorprone.xml +++ b/pmd-java/src/main/resources/category/java/errorprone.xml @@ -3052,11 +3052,11 @@ StringBuilder sb4 = new StringBuilder("c"); class="net.sourceforge.pmd.lang.rule.XPathRule" externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#suspiciousequalsmethodname"> -The method name and parameter number are suspiciously close to Object.equals, which can denote an -intention to override it. However, the method does not override Object.equals, but overloads it instead. -Overloading Object.equals method is confusing for other programmers, error-prone and hard to maintain, -especially when using inheritance, because @Override annotations used in subclasses can provide a false -sense of security. For more information on Object.equals method, see Effective Java, 3rd Edition, +The method name and parameter number are suspiciously close to `Object.equals`, which can denote an +intention to override it. However, the method does not override `Object.equals`, but overloads it instead. +Overloading `Object.equals` method is confusing for other programmers, error-prone and hard to maintain, +especially when using inheritance, because `@Override` annotations used in subclasses can provide a false +sense of security. For more information on `Object.equals` method, see Effective Java, 3rd Edition, Item 10: Obey the general contract when overriding equals. 2 From 99e86557e8d1e6cf4c64819ba581a286d7e88096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Tue, 25 Aug 2020 14:40:24 +0200 Subject: [PATCH 4/4] Update release notes, refs 2724 --- docs/pages/release_notes.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 74e1ad52fa..34f16eb60f 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -96,6 +96,7 @@ For the changes, see [PMD Designer Changelog](https://github.com/pmd/pmd-designe * [#2108](https://github.com/pmd/pmd/issues/2108): \[java] \[doc] ImmutableField rule: Description should clarify shallow immutability * [#2461](https://github.com/pmd/pmd/issues/2461): \[java] ExcessiveParameterListRule must ignore a private constructor * java-errorprone + * [#2264](https://github.com/pmd/pmd/issues/2264): \[java] SuspiciousEqualsMethodName: Improve description about error-prone overloading of equals() * [#2410](https://github.com/pmd/pmd/issues/2410): \[java] ProperCloneImplementation not valid for final class * [#2431](https://github.com/pmd/pmd/issues/2431): \[java] InvalidLogMessageFormatRule throws IndexOutOfBoundsException when only logging exception message * [#2439](https://github.com/pmd/pmd/issues/2439): \[java] AvoidCatchingThrowable can not detect the case: catch (java.lang.Throwable t) @@ -178,6 +179,7 @@ are deprecated as internal API. * [#2700](https://github.com/pmd/pmd/pull/2700): \[java] Fix OnlyOneReturn code example - [Jan-Lukas Else](https://github.com/jlelse) * [#2722](https://github.com/pmd/pmd/pull/2722): \[doc] \[java] ImmutableField: extend description, fixes #2108 - [Mateusz Stefanski](https://github.com/mateusz-stefanski) * [#2723](https://github.com/pmd/pmd/pull/2723): \[doc] \[java] SimplifyStartsWith: update description and example, fixes #1868 - [Mateusz Stefanski](https://github.com/mateusz-stefanski) +* [#2724](https://github.com/pmd/pmd/pull/2724): \[doc] [java] SuspiciousEqualsMethodName: update description, fixes #2264 - [Mateusz Stefanski](https://github.com/mateusz-stefanski) * [#2725](https://github.com/pmd/pmd/pull/2725): Cleanup: change valueOf to parse when we need primitive return value. - [XenoAmess](https://github.com/XenoAmess) * [#2726](https://github.com/pmd/pmd/pull/2726): Cleanup: replace StringBuffer with StringBuilder - [XenoAmess](https://github.com/XenoAmess) * [#2727](https://github.com/pmd/pmd/pull/2727): Cleanup: replace indexOf() < 0 with contains - [XenoAmess](https://github.com/XenoAmess)