Skip to content

Singleton enum cases (marked Serializable) are incorrectly serialized #9179

Closed
@akouryy

Description

@akouryy

Minimized code

Running twice with 0.25.0-RC1:

import java.io._

enum A:
  case B

object Main extends App:
  val file = File("/tmp/EnumSerialization.dat")

  if file.exists
    val a = ObjectInputStream(FileInputStream(file)).readObject().asInstanceOf[A]
    println(a == A.B)
    a match
      case A.B => // passes exhaustivity check
  else
    ObjectOutputStream(FileOutputStream(file)).writeObject(A.B)

Output

On second execution:

false

[error] java.lang.ExceptionInInitializerError
...
[error] Caused by: scala.MatchError: B (of class A$$anon$1)

Expectation

I expected a == A.B because it is marked Serializable by default.

I think there are two options:

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions