Scala Programming Language
  1. Scala Programming Language
  2. SI-6935

unit value equality is broken when deserialized

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Scala 2.10.2-RC1
    • Component/s: None
    • Labels:
      None
    • Environment:

      scala 2.10

      Description

      When () is deserialized, it no longer passes the equality check with itself.

      import java.io._
      val bytes = new ByteArrayOutputStream()
      val out = new ObjectOutputStream(bytes)
      out.writeObject(())
      out.close()
      val buf = bytes.toByteArray
      buf: Array[Byte] = Array(-84, -19, 0, 5, 115, 114, 0, 23, 115, 99, 97, 108,
      97, 46, 114, 117, 110, 116, 105, 109, 101, 46, 66, 111, 120, 101, 100, 85,
      110, 105, 116, 116, -90, 125, 71, 29, -20, -53, -102, 2, 0, 0, 120, 112)
      val in = new ObjectInputStream(new ByteArrayInputStream(buf))
      val unit = in.readObject()
      unit == ()
      res4: Boolean = false

      The last "unit == ()" should evaluate to true.

        Activity

        Hide
        Stephen Haberman added a comment -

        I did not mean to set the Priority Blocker, but it seemed like JIRA would not allow me to change it to anything else.

        Show
        Stephen Haberman added a comment - I did not mean to set the Priority Blocker, but it seemed like JIRA would not allow me to change it to anything else.
        Hide
        Jan Vanek added a comment -

        Adding readResolve to the scala.runtime.BoxedUnit fixes the issue.

        package scala.runtime;

        public final class BoxedUnit implements java.io.Serializable {
        ...
        private Object readResolve()

        { return UNIT; }

        }

        Show
        Jan Vanek added a comment - Adding readResolve to the scala.runtime.BoxedUnit fixes the issue. package scala.runtime; public final class BoxedUnit implements java.io.Serializable { ... private Object readResolve() { return UNIT; } }
        Hide
        Stephen Haberman added a comment -

        Hi Jan, thanks!

        Would you like to submit a pull request with that fix?

        I can attempt to do that if you'd rather not be bothered.

        Show
        Stephen Haberman added a comment - Hi Jan, thanks! Would you like to submit a pull request with that fix? I can attempt to do that if you'd rather not be bothered.
        Hide
        Jan Vanek added a comment -

        Hi Stephen, please do that. I want to learn it too, but I'll likely get to it during the weekend, and I don't know what does it take. So it is better that you do it now. Regards...

        Show
        Jan Vanek added a comment - Hi Stephen, please do that. I want to learn it too, but I'll likely get to it during the weekend, and I don't know what does it take. So it is better that you do it now. Regards...
        Hide
        Jan Vanek added a comment -

        Hi Stephen, please do the patch. In case you won't find time, I think we could notify someone from scala team. I won't get to it, loaded. Best...

        Show
        Jan Vanek added a comment - Hi Stephen, please do the patch. In case you won't find time, I think we could notify someone from scala team. I won't get to it, loaded. Best...
        Hide
        Vinicius Miana Bezerra added a comment -

        I am taking on this.

        Show
        Vinicius Miana Bezerra added a comment - I am taking on this.
        Show
        Vinicius Miana Bezerra added a comment - Fix in: https://github.com/scala/scala/pull/2097

          People

          • Assignee:
            Vinicius Miana Bezerra
            Reporter:
            Stephen Haberman
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development