Skip to content

Commit 2d4b5ea

Browse files
MaxGekksrowen
authored andcommitted
[SPARK-30676][CORE][TESTS] Eliminate warnings from deprecated constructors of java.lang.Integer and java.lang.Double
### What changes were proposed in this pull request? - Replace `new Integer(0)` by a serializable instance in RDD.scala - Use `.valueOf()` instead of constructors of `java.lang.Integer` and `java.lang.Double` because constructors has been deprecated, see https://docs.oracle.com/javase/9/docs/api/java/lang/Integer.html ### Why are the changes needed? This fixes the following warnings: 1. RDD.scala:240: constructor Integer in class Integer is deprecated: see corresponding Javadoc for more information. 2. MutableProjectionSuite.scala:63: constructor Integer in class Integer is deprecated: see corresponding Javadoc for more information. 3. UDFSuite.scala:446: constructor Integer in class Integer is deprecated: see corresponding Javadoc for more information. 4. UDFSuite.scala:451: constructor Double in class Double is deprecated: see corresponding Javadoc for more information. 5. HiveUserDefinedTypeSuite.scala:71: constructor Double in class Double is deprecated: see corresponding Javadoc for more information. ### Does this PR introduce any user-facing change? No ### How was this patch tested? - By RDDSuite, MutableProjectionSuite, UDFSuite and HiveUserDefinedTypeSuite Closes #27399 from MaxGekk/eliminate-warning-part4. Authored-by: Maxim Gekk <[email protected]> Signed-off-by: Sean Owen <[email protected]>
1 parent 387ce89 commit 2d4b5ea

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

core/src/main/scala/org/apache/spark/rdd/RDD.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,10 @@ abstract class RDD[T: ClassTag](
234234
* because DAGs are acyclic, and we only ever hold locks for one path in that DAG, there is no
235235
* chance of deadlock.
236236
*
237-
* The use of Integer is simply so this is serializable -- executors may reference the shared
238-
* fields (though they should never mutate them, that only happens on the driver).
237+
* Executors may reference the shared fields (though they should never mutate them,
238+
* that only happens on the driver).
239239
*/
240-
private val stateLock = new Integer(0)
240+
private val stateLock = new Serializable {}
241241

242242
// Our dependencies and partitions will be gotten by calling subclass's methods below, and will
243243
// be overwritten when we're checkpointed

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MutableProjectionSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class MutableProjectionSuite extends SparkFunSuite with ExpressionEvalHelper {
6060
val scalaValues = Seq("abc", BigDecimal(10),
6161
IntervalUtils.stringToInterval(UTF8String.fromString("interval 1 day")),
6262
Array[Byte](1, 2), Array("123", "456"), Map(1 -> "a", 2 -> "b"), Row(1, "a"),
63-
new java.lang.Integer(5))
63+
Integer.valueOf(5))
6464
val inputRow = InternalRow.fromSeq(scalaValues.zip(variableLengthTypes).map {
6565
case (v, dataType) => CatalystTypeConverters.createToCatalystConverter(dataType)(v)
6666
})

sql/core/src/test/scala/org/apache/spark/sql/UDFSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,12 @@ class UDFSuite extends QueryTest with SharedSparkSession {
443443
test("SPARK-25044 Verify null input handling for primitive types - with udf(Any, DataType)") {
444444
val f = udf((x: Int) => x, IntegerType)
445445
checkAnswer(
446-
Seq(new Integer(1), null).toDF("x").select(f($"x")),
446+
Seq(Integer.valueOf(1), null).toDF("x").select(f($"x")),
447447
Row(1) :: Row(0) :: Nil)
448448

449449
val f2 = udf((x: Double) => x, DoubleType)
450450
checkAnswer(
451-
Seq(new java.lang.Double(1.1), null).toDF("x").select(f2($"x")),
451+
Seq(java.lang.Double.valueOf(1.1), null).toDF("x").select(f2($"x")),
452452
Row(1.1) :: Row(0.0) :: Nil)
453453

454454
}

sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveUserDefinedTypeSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ class TestUDF extends GenericUDF {
6868

6969
override def evaluate(arguments: Array[GenericUDF.DeferredObject]): AnyRef = {
7070
val point = data.getList(arguments(0).get())
71-
new java.lang.Double(point.get(0).asInstanceOf[Double])
71+
java.lang.Double.valueOf(point.get(0).asInstanceOf[Double])
7272
}
7373
}

0 commit comments

Comments
 (0)