question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No valid constructor

See original GitHub issue

First of all: thanks for this awesome library! I hope it finds its way into core Scala proper 😃

I’m having some issues with enums that override entryName when I use them together with Spark. I think the problem is in deserializing enums. This is the relevant enum code:

sealed abstract class PhBoardingStatus(override val entryName: String) extends EnumEntry
object PhBoardingStatus extends Enum[PhBoardingStatus] {

  val values: IndexedSeq[PhBoardingStatus] = findValues

  case object All           extends PhBoardingStatus("ALL")
  case object Closed        extends PhBoardingStatus("BC")
  case object Ignored       extends PhBoardingStatus("BI")
  case object NotOpen       extends PhBoardingStatus("BN")
  case object Open          extends PhBoardingStatus("BO")
  case object Suspended     extends PhBoardingStatus("BS")
}

When using this enum in Spark code, this stacktrace gets thrown:

2017-05-16 09:22:37 WARN  org.apache.spark.scheduler.TaskSetManager:66 - Lost task 0.0 in stage 17.0 (TID 33, kl1393d4.is.klmcorp.net): java.io.InvalidClassException: com.klm.flight720.dataSources.ph.PhBoardingStatus$Closed$; no valid constructor
	at java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:150)
	at java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:790)
	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1775)
	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
	at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2000)
	at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1924)
	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1801)
	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
	at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2000)
	at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1924)
	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1801)
	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
	at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
	at org.apache.spark.serializer.JavaDeserializationStream.readObject(JavaSerializer.scala:75)
	at org.apache.spark.serializer.DeserializationStream.readValue(Serializer.scala:159)
	at org.apache.spark.serializer.DeserializationStream$$anon$2.getNext(Serializer.scala:189)
	at org.apache.spark.serializer.DeserializationStream$$anon$2.getNext(Serializer.scala:186)
        ...

I assume this is because our abstract class only has a cosntructor with 1 argument, and no no-args constructor. Any idea how I can solve this?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
tsabrancommented, Jul 20, 2018

I’ve added this in the sealed abstract class instead, which I find less verbose and seems to work fine too:

    def this() = this("")

Yet I’m not familiar enough with this to understand why we need this no-param constructor and if it could be fixed directly in the EnumEntry…

3reactions
lloydmetacommented, May 16, 2017

I think case objects already extend Serializable by default, so the problem might be as you said; the lack of a no-args constructor on the parent.

Perhaps something like this could work?

sealed trait PhBoardingStatus extends EnumEntry

object PhBoardingStatus extends Enum[PhBoardingStatus] {

  val values = findValues

  case object All       extends PhBoardingStatus { override val entryName = "ALL"}
  case object Closed    extends PhBoardingStatus { override val entryName = "BC" }
  case object Ignored   extends PhBoardingStatus { override val entryName = "BI" }
  case object NotOpen   extends PhBoardingStatus { override val entryName = "BN" }
  case object Open      extends PhBoardingStatus { override val entryName = "BO" }
  case object Suspended extends PhBoardingStatus { override val entryName = "BS" }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

java.io.InvalidClassException: no valid constructor
An object is serializable (itself implements the Serializable interface) even if its superclass is not. However, the first superclass in the ...
Read more >
java.io.InvalidClassException: no valid constructor
When this InvalidClassException:no valid constructor is thrown? This type of exception is thrown when inheritance is involved in the program.
Read more >
Getting java.io.InvalidClassException (no valid constructor ...
Hi,. case objects are still objects (i.e. not static), so they will be serialized. Are you sure that java.awt.Color is serializable? If not...
Read more >
No Valid constructor error, even with default constuctor
Hi all, The following code is giving me the error: java.io.InValidClassException: test; test; no valid constructor.
Read more >
Sporadic java.io.InvalidClassException: no valid constructor ...
Version 7.1.2 corrects an issue in PingFederate v7.1.1 with artifact binding in clustered deployments that resulted in sporadic failed transactions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found