title: Identify which object is not serializable in Apache-Flink
body: <p>I am writing a Flink transformer and I have a custom object <code>Histogram</code> with the following attributes:</p>
  
  <pre><code>case class Histogram(
    nRows: Int,
    nCols: Int,
    min: Int,
    step: Double,
    private val countMatrix: Array[ArrayBuffer[Double]],
    private val cutMatrixL1: Array[ArrayBuffer[Double]],
    val distribMatrixL1: Array[ArrayBuffer[Map[Int, Double]]],
    private val distribMatrixL2: Array[ArrayBuffer[Map[Int, Double]]],
    private val cutMatrixL2: ArrayBuffer[ArrayBuffer[Double]])
    extends Serializable {
      ???
  }
  </code></pre>
  
  <p>This is my <code>FitOperation</code>:</p>
  
  <pre><code>implicit val fitOp = new FitOperation[PIDiscretizerTransformer, LabeledVector] {
      override def fit(
                        instance: PIDiscretizerTransformer,
                        fitParameters: ParameterMap,
                        input: DataSet[LabeledVector]): Unit = {
  
        // get params...
  
        val metric = input.map { x ⇒
          // (instance, histrogram totalCount)
          (x, Histogram(nAttrs, l1InitialBins, min, instance.step), 1)
        }.reduce { (m1, m2) ⇒
          // Update Layer 1
          val updatedL1 = updateL1(m1._1, m1._2, instance.step, initialElems, alpha, m1._3)
  
          //         Update Layer 2 if neccesary
          val updatedL2 = if (m1._3 % l2updateExamples == 0) {
            updateL2(m1._1, updatedL1)
          } else updatedL1
  
          (m2._1, updatedL2, m1._3 + 1)
        }.map(_._2)
  
        //      instance.metricsOption = Some(metric)
      }
    }
  </code></pre>
  
  <p>This works well, but if I uncomment the last line: <code>instance.metricsOption = Some(metric)</code> I get a <code>java.io.NotSerializableException: org.apache.flink.api.scala.DataSet</code></p>
  
  <p>How could I find which object in my class <code>Histogram</code> is causing the problem? As far as I know <code>ArrayBuffer</code> is serializable, so is Map. Although I've found this SO question: </p>
  
  <p><a href="https://stackoverflow.com/q/32900862/1612432">Map can not be serializable in scala?</a></p>
  
  <p>which says <code>.mapValues</code> is not serializable, but I am not using <code>.mapValues</code> anywhere.</p>