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

@transient object - does not work and no error/warning. #5773

Open
scabug opened this Issue May 8, 2012 · 4 comments

Comments

Projects
None yet
1 participant
@scabug
Copy link

scabug commented May 8, 2012

"@transient object" does not work and does not generate an error. Instead the compiler silently accepts the annotation and then simply ignores it.

object ExpMain {
 
  def main(args: Array[String]) {
    import java.io._
   
    val test = new TransientTest
    test.nested.value = 1
    test.transientNested.value = 1
   
    val bytes = new ByteArrayOutputStream
    val out = new ObjectOutputStream(bytes)
    out.writeObject(test)
    out.close()
    val in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray))
    val restored = in.readObject.asInstanceOf[TransientTest]
   
    println("nested.value equal: " + (test.nested.value == restored.nested.value))
    println("transientNested.value equal: " + (test.transientNested.value == restored.transientNested.value))
  }
}

class TransientTest extends Serializable {
  object nested extends Serializable { var value = 0 }
  @transient object transientNested extends Serializable { var value = 0 }
}
@scabug

This comment has been minimized.

Copy link
Author

scabug commented May 8, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5773?orig=1
Reporter: @lexn82
Affected Versions: 2.9.2

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Mar 15, 2013

@adriaanm said:
Un-assigning to foster work stealing, as announced in https://groups.google.com/forum/?fromgroups=#!topic/scala-internals/o8WG4plpNkw

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Jul 10, 2013

@adriaanm said:
Unassigning and rescheduling to M6 as previous deadline was missed.

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Apr 17, 2016

Sonnenschein (sonnenschein) said:
I also spent some time to test with the following result:

@transient for a nested object works only in an enclosing object. Unfortunately it does not work in any enclosing trait or class.

See also object ScalaObjectSerialization in TSerializable.scala.

@scabug scabug added the backend label Apr 7, 2017

@scabug scabug added this to the Backlog milestone Apr 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment