You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by do...@apache.org on 2022/02/11 03:18:29 UTC
[spark] branch master updated: [SPARK-38125][BUILD][SQL] Use static factory methods instead of the deprecated `Byte/Short/Integer/Long` constructors
This is an automated email from the ASF dual-hosted git repository.
dongjoon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 23cd319 [SPARK-38125][BUILD][SQL] Use static factory methods instead of the deprecated `Byte/Short/Integer/Long` constructors
23cd319 is described below
commit 23cd3190f7453010a0311b8639158e8b586997e2
Author: Dongjoon Hyun <do...@apache.org>
AuthorDate: Thu Feb 10 19:17:15 2022 -0800
[SPARK-38125][BUILD][SQL] Use static factory methods instead of the deprecated `Byte/Short/Integer/Long` constructors
### What changes were proposed in this pull request?
This PR aims to use static factor methods instead of the deprecated `Integer` constructors and add Java/Scala linter rules to enforce new styles.
### Why are the changes needed?
`Byte/Short/Integer/Long` constructors are deprecated in Java 9.
- https://docs.oracle.com/javase/9/docs/api/java/lang/Byte.html#Byte-byte-
- https://docs.oracle.com/javase/9/docs/api/java/lang/Byte.html#Byte-java.lang.String-
- https://docs.oracle.com/javase/9/docs/api/java/lang/Short.html#Short-short-
- https://docs.oracle.com/javase/9/docs/api/java/lang/Short.html#Short-java.lang.String-
- https://docs.oracle.com/javase/9/docs/api/java/lang/Integer.html#Integer-int-
- https://docs.oracle.com/javase/9/docs/api/java/lang/Integer.html#Integer-java.lang.String-
- https://docs.oracle.com/javase/9/docs/api/java/lang/Long.html#Long-long-
- https://docs.oracle.com/javase/9/docs/api/java/lang/Long.html#Long-java.lang.String-
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Pass the CIs with the newly added Scalastyle and Java Checkstyle.
Closes #35414 from dongjoon-hyun/SPARK-38125.
Authored-by: Dongjoon Hyun <do...@apache.org>
Signed-off-by: Dongjoon Hyun <do...@apache.org>
---
dev/checkstyle.xml | 4 ++++
scalastyle-config.xml | 5 +++++
.../src/test/java/test/org/apache/spark/sql/JavaDatasetSuite.java | 4 ++--
.../src/test/scala/org/apache/spark/sql/internal/SQLConfSuite.scala | 2 +-
.../org/apache/spark/sql/hive/thriftserver/SparkSQLCLIService.scala | 4 ++--
5 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/dev/checkstyle.xml b/dev/checkstyle.xml
index b6abfb5..6c93ff9 100644
--- a/dev/checkstyle.xml
+++ b/dev/checkstyle.xml
@@ -189,6 +189,10 @@
<property name="format" value="Objects\.toStringHelper"/>
<property name="message" value="Avoid using Object.toStringHelper. Use ToStringBuilder instead." />
</module>
+ <module name="RegexpSinglelineJava">
+ <property name="format" value="new (java\.lang\.)?(Byte|Integer|Long|Short)\("/>
+ <property name="message" value="Use static factory 'valueOf' or 'parseXXX' instead of the deprecated constructors." />
+ </module>
<module name="IllegalImport">
<property name="illegalPkgs" value="org.apache.log4j" />
</module>
diff --git a/scalastyle-config.xml b/scalastyle-config.xml
index 32f1f14..9585785 100644
--- a/scalastyle-config.xml
+++ b/scalastyle-config.xml
@@ -324,6 +324,11 @@ This file is divided into 3 sections:
<customMessage>Omit braces in case clauses.</customMessage>
</check>
+ <check level="error" class="org.scalastyle.file.RegexChecker" enabled="true">
+ <parameters><parameter name="regex">new (java\.lang\.)?(Byte|Integer|Long|Short)\(</parameter></parameters>
+ <customMessage>Use static factory 'valueOf' or 'parseXXX' instead of the deprecated constructors.</customMessage>
+ </check>
+
<!-- SPARK-16877: Avoid Java annotations -->
<check level="error" class="org.scalastyle.scalariform.OverrideJavaChecker" enabled="true"></check>
diff --git a/sql/core/src/test/java/test/org/apache/spark/sql/JavaDatasetSuite.java b/sql/core/src/test/java/test/org/apache/spark/sql/JavaDatasetSuite.java
index 6ff53a8..22978fb 100644
--- a/sql/core/src/test/java/test/org/apache/spark/sql/JavaDatasetSuite.java
+++ b/sql/core/src/test/java/test/org/apache/spark/sql/JavaDatasetSuite.java
@@ -279,7 +279,7 @@ public class JavaDatasetSuite implements Serializable {
Assert.assertTrue(prevState.isUpdated());
Assert.assertFalse(prevState.isRemoved());
Assert.assertTrue(prevState.exists());
- Assert.assertEquals(new Integer(9), prevState.get());
+ Assert.assertEquals(Integer.valueOf(9), prevState.get());
Assert.assertEquals(0L, prevState.getCurrentProcessingTimeMs());
Assert.assertEquals(1000L, prevState.getCurrentWatermarkMs());
Assert.assertEquals(Optional.of(1500L), prevState.getTimeoutTimestampMs());
@@ -289,7 +289,7 @@ public class JavaDatasetSuite implements Serializable {
Assert.assertTrue(prevState.isUpdated());
Assert.assertFalse(prevState.isRemoved());
Assert.assertTrue(prevState.exists());
- Assert.assertEquals(new Integer(18), prevState.get());
+ Assert.assertEquals(Integer.valueOf(18), prevState.get());
prevState = TestGroupState.create(
Optional.of(9), GroupStateTimeout.EventTimeTimeout(), 0L, Optional.of(1000L), true);
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/internal/SQLConfSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/internal/SQLConfSuite.scala
index abde486..a589d4e 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/internal/SQLConfSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/internal/SQLConfSuite.scala
@@ -469,7 +469,7 @@ class SQLConfSuite extends QueryTest with SharedSparkSession {
if (i == 0) {
assert(zone === "Z")
} else {
- assert(zone === String.format("%+03d:00", new Integer(i)))
+ assert(zone === String.format("%+03d:00", Integer.valueOf(i)))
}
}
val e2 = intercept[ParseException](sql("set time zone interval 19 hours"))
diff --git a/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLCLIService.scala b/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLCLIService.scala
index bc4b64c..d2c0235 100644
--- a/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLCLIService.scala
+++ b/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLCLIService.scala
@@ -138,7 +138,7 @@ private[thriftserver] trait ReflectedCompositeService { this: AbstractService =>
serviceStartCount += 1
}
// Emulating `AbstractService.start`
- val startTime = new java.lang.Long(System.currentTimeMillis())
+ val startTime = java.lang.Long.valueOf(System.currentTimeMillis())
setAncestorField(this, 3, "startTime", startTime)
invoke(classOf[AbstractService], this, "ensureCurrentState", classOf[STATE] -> STATE.INITED)
invoke(classOf[AbstractService], this, "changeState", classOf[STATE] -> STATE.STARTED)
@@ -147,7 +147,7 @@ private[thriftserver] trait ReflectedCompositeService { this: AbstractService =>
case NonFatal(e) =>
logError(s"Error starting services $getName", e)
invoke(classOf[CompositeService], this, "stop",
- classOf[Int] -> new Integer(serviceStartCount))
+ classOf[Int] -> Integer.valueOf(serviceStartCount))
throw HiveThriftServerErrors.failedToStartServiceError(getName, e)
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org