Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Prevent null input to setters.
  • Loading branch information
viirya committed Apr 5, 2018
commit 96a8fe6102d8d175003392a14d67cd74c0b86319
Original file line number Diff line number Diff line change
Expand Up @@ -1418,8 +1418,7 @@ case class InitializeJavaBean(beanInstance: Expression, setters: Map[String, Exp
case (name, expr) =>
// Looking for known type mapping first, then using Class attached in `ObjectType`.
// Finally also looking for general `Object`-type parameter for generic methods.
val paramTypes = CallMethodViaReflection.typeMapping.getOrElse(expr.dataType,
Seq(expr.dataType.asInstanceOf[ObjectType].cls)) ++ Seq(classOf[Object])
val paramTypes = ScalaReflection.expressionJavaClasses(Seq(expr)) ++ Seq(classOf[Object])
val methods = paramTypes.flatMap { fieldClass =>
try {
Some(beanClass.getDeclaredMethod(name, fieldClass))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,18 @@ class ObjectExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
val initializeBean = InitializeJavaBean(
Literal.fromObject(new TestBean),
Map("setNonPrimitive" -> Literal(null)))
evaluateWithoutCodegen(initializeBean, InternalRow.fromSeq(Seq()))
intercept[NullPointerException] {
evaluateWithoutCodegen(initializeBean, InternalRow.fromSeq(Seq()))
}.getMessage.contains("The parameter value for setters in `InitializeJavaBean` can not be null")
intercept[NullPointerException] {
evaluateWithGeneratedMutableProjection(initializeBean, InternalRow.fromSeq(Seq()))
}.getMessage.contains("The parameter value for setters in `InitializeJavaBean` can not be null")

val initializeBean2 = InitializeJavaBean(
Literal.fromObject(new TestBean),
Map("setNonPrimitive" -> Literal("string")))
evaluateWithoutCodegen(initializeBean2, InternalRow.fromSeq(Seq()))
evaluateWithGeneratedMutableProjection(initializeBean2, InternalRow.fromSeq(Seq()))
}

test("SPARK-23585: UnwrapOption should support interpreted execution") {
Expand Down