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

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

Open
scabug opened this issue May 8, 2012 · 3 comments
Open

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

scabug opened this issue May 8, 2012 · 3 comments

Comments

@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]): Unit = {
    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
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
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
@scala scala deleted a comment from scabug Dec 22, 2023
@scala scala deleted a comment from scabug Dec 22, 2023
@SethTisue
Copy link
Member

Same results in Scala 3.4.0-RC1-bin-20231220-d3fafd6-NIGHTLY.

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

No branches or pull requests

2 participants