Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unit value equality is broken when deserialized #6935

Closed
scabug opened this issue Jan 7, 2013 · 8 comments
Closed

unit value equality is broken when deserialized #6935

scabug opened this issue Jan 7, 2013 · 8 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Jan 7, 2013

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.

@scabug
Copy link
Author

scabug commented Jan 7, 2013

Imported From: https://issues.scala-lang.org/browse/SI-6935?orig=1
Reporter: Stephen Haberman (shaberman)

@scabug
Copy link
Author

scabug commented Jan 7, 2013

Stephen Haberman (shaberman) said:
I did not mean to set the Priority Blocker, but it seemed like JIRA would not allow me to change it to anything else.

@scabug
Copy link
Author

scabug commented Jan 15, 2013

Jan Vanek (j3vanek) said:
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;
}
}

@scabug
Copy link
Author

scabug commented Jan 15, 2013

Stephen Haberman (shaberman) said:
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.

@scabug
Copy link
Author

scabug commented Jan 15, 2013

Jan Vanek (j3vanek) said:
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...

@scabug
Copy link
Author

scabug commented Jan 28, 2013

Jan Vanek (j3vanek) said:
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...

@scabug
Copy link
Author

scabug commented Feb 8, 2013

@ViniciusMiana said:
I am taking on this.

@scabug
Copy link
Author

scabug commented Feb 8, 2013

@ViniciusMiana said:
Fix in: scala/scala#2097

@scabug scabug closed this as completed Feb 11, 2013
@scabug scabug added the blocker label Apr 7, 2017
@scabug scabug added this to the 2.10.2-RC1 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants