Skip to content

Commit c532f82

Browse files
committed
[SPARK-35609][BUILD] Add style rules to prohibit to use a Guava's API which is incompatible with newer versions
### What changes were proposed in this pull request? This PR adds rules to `checkstyle.xml` and `scalastyle-config.xml` to avoid introducing `Objects.toStringHelper` a Guava's API which is no longer present in newer Guava. ### Why are the changes needed? SPARK-30272 (#26911) replaced `Objects.toStringHelper` which is an APIs Guava 14 provides with `commons.lang3` API because `Objects.toStringHelper` is no longer present in newer Guava. But toStringHelper was introduced into Spark again and replaced them in SPARK-35420 (#32567). I think it's better to have a style rule to avoid such repetition. SPARK-30272 replaced some APIs aside from `Objects.toStringHelper` but `Objects.toStringHelper` seems to affect Spark for now so I add rules only for it. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? I confirmed that `lint-java` and `lint-scala` detect the usage of `toStringHelper` and let the lint check fail. ``` $ dev/lint-java exec: curl --silent --show-error -L https://downloads.lightbend.com/scala/2.12.14/scala-2.12.14.tgz Using `mvn` from path: /opt/maven/3.6.3//bin/mvn Checkstyle checks failed at following occurrences: [ERROR] src/main/java/org/apache/spark/network/protocol/OneWayMessage.java:[78] (regexp) RegexpSinglelineJava: Avoid using Object.toStringHelper. Use ToStringBuilder instead. $ dev/lint-scala Scalastyle checks failed at following occurrences: [error] /home/kou/work/oss/spark/core/src/main/scala/org/apache/spark/rdd/RDD.scala:93:25: Avoid using Object.toStringHelper. Use ToStringBuilder instead. [error] Total time: 25 s, completed 2021/06/02 16:18:25 ``` Closes #32740 from sarutak/style-rule-for-guava. Authored-by: Kousuke Saruta <[email protected]> Signed-off-by: Kousuke Saruta <[email protected]>
1 parent 2658bc5 commit c532f82

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

dev/checkstyle.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@
185185
<property name="format" value="throw new \w+Error\("/>
186186
<property name="message" value="Avoid throwing error in application code."/>
187187
</module>
188-
188+
<module name="RegexpSinglelineJava">
189+
<property name="format" value="Objects\.toStringHelper"/>
190+
<property name="message" value="Avoid using Object.toStringHelper. Use ToStringBuilder instead." />
191+
</module>
189192
</module>
190193
</module>

scalastyle-config.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,4 +397,8 @@ This file is divided into 3 sections:
397397
<parameters><parameter name="ignore">-1,0,1,2,3</parameter></parameters>
398398
</check>
399399

400+
<check customId="GuavaToStringHelper" level="error" class="org.scalastyle.file.RegexChecker" enabled="true">
401+
<parameters><parameter name="regex">Objects.toStringHelper</parameter></parameters>
402+
<customMessage>Avoid using Object.toStringHelper. Use ToStringBuilder instead.</customMessage>
403+
</check>
400404
</scalastyle>

0 commit comments

Comments
 (0)