title: Two similar udf in Spark scala unconventional date conversion producing different results
body: <p>I've got a simple Spark df:</p>
  
  <pre><code>val df = Seq("24-12-2017","25-01-2016").toDF("dates")
  df.show()
  +----------+
  |     dates|
  +----------+
  |24-12-2017|
  |25-01-2016|
  +----------+
  </code></pre>
  
  <p>To convert it to desired format I use following snippet:</p>
  
  <pre><code>import java.text.SimpleDateFormat
  
  def fmt(d:String) = {
      val f = new SimpleDateFormat("dd-MM-yyyy").parse(d).getTime
      new java.sql.Timestamp(f)
  }
  
  val fmtTimestamp = udf(fmt(_:String):java.sql.Timestamp)
  
  df.select($"dates",fmtTimestamp($"dates")).show
  +----------+-------------------+
  |     dates|         UDF(dates)|
  +----------+-------------------+
  |24-12-2017|2017-12-24 00:00:00|
  |25-01-2016|2016-01-25 00:00:00|
  +----------+-------------------+
  </code></pre>
  
  <p>and everting goes as expected.</p>
  
  <p>However, when I try simplified version everething is crushed:</p>
  
  <pre><code>import java.text.SimpleDateFormat
  
  def fmt(d:String) = {
      new SimpleDateFormat("dd-MM-yyyy").parse(d)
  }
  
  val fmtTimestamp = udf(fmt(_:String):java.util.Date)
  
  java.lang.UnsupportedOperationException: Schema for type java.util.Date is not supported
    org.apache.spark.sql.catalyst.ScalaReflection$$anonfun$schemaFor$1.apply(ScalaReflection.scala:789)
    org.apache.spark.sql.catalyst.ScalaReflection$$anonfun$schemaFor$1.apply(ScalaReflection.scala:724)
    scala.reflect.internal.tpe.TypeConstraints$UndoLog.undo(TypeConstraints.scala:56)
    org.apache.spark.sql.catalyst.ScalaReflection$class.cleanUpReflectionObjects(ScalaReflection.scala:906)
    org.apache.spark.sql.catalyst.ScalaReflection$.cleanUpReflectionObjects(ScalaReflection.scala:46)
    org.apache.spark.sql.catalyst.ScalaReflection$.schemaFor(ScalaReflection.scala:723)
    org.apache.spark.sql.catalyst.ScalaReflection$.schemaFor(ScalaReflection.scala:720)
    org.apache.spark.sql.functions$.udf(functions.scala:3898)
    $sess.cmd17Wrapper$Helper.&lt;init&gt;(cmd17.sc:7)
    $sess.cmd17Wrapper.&lt;init&gt;(cmd17.sc:718)
    $sess.cmd17$.&lt;init&gt;(cmd17.sc:563)
    $sess.cmd17$.&lt;clinit&gt;(cmd17.sc:-1)
  </code></pre>
  
  <p>What could be a reason for 1st case completing and 2nd crushing?</p>