FindBugs issue with transient

P

Paul Tomblin

I just insalled the FindBugs plugin in Eclipse, and while it whines about
a bunch of stuff that I don't care about, it's found a few real ones. But
there is a warning that I don't understand at all. A transient variable
in a serializable class is marked:

H B Se: The field <variable name> is transient but isn't set by
deserialization.

What does that mean?
 
J

Jeff Higgins

Paul said:
Excuse me, I didn't mean that I didn't know why I put "transient" in my
own program, I meant to ask why FindBugs thinks it is a problem that it
isn't set by deserialization. I initialize the variable in the default
ctor. Would it be happier if I initialized it in the declaration line?
RTFM
 
D

Daniel Pitts

Paul said:
Excuse me, I didn't mean that I didn't know why I put "transient" in my
own program, I meant to ask why FindBugs thinks it is a problem that it
isn't set by deserialization. I initialize the variable in the default
ctor. Would it be happier if I initialized it in the declaration line?
Deserialization skips the default ctor, so you have a bug. It also
skips the default initializers. If you need it set to a default value,
you must set it after deserialization.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top