FindBugs issue with transient

Discussion in 'Java' started by Paul Tomblin, Jul 23, 2008.

  1. Paul Tomblin

    Paul Tomblin Guest

    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?

    --
    Paul Tomblin <> http://blog.xcski.com/
    Never underestimate the bandwidth of a station wagon full of
    tapes hurtling down the highway.
    -- Andrew Tannenbaum possibly quoting Warren Jackson
    Paul Tomblin, Jul 23, 2008
    #1
    1. Advertising

  2. Paul Tomblin

    Jeff Higgins Guest

    Paul Tomblin wrote:
    >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?
    >


    <http://en.wikibooks.org/wiki/Java_Programming/Keywords/transient>
    Jeff Higgins, Jul 23, 2008
    #2
    1. Advertising

  3. Paul Tomblin

    Jeff Higgins Guest

    Jeff Higgins wrote:
    >
    > Paul Tomblin wrote:
    >>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?
    >>

    >
    > <http://en.wikibooks.org/wiki/Java_Programming/Keywords/transient>
    >


    <http://en.wikipedia.org/wiki/Serialization#Java>
    Jeff Higgins, Jul 23, 2008
    #3
  4. Paul Tomblin

    Paul Tomblin Guest

    In a previous article, "Jeff Higgins" <> said:
    >
    >Paul Tomblin wrote:
    >>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?
    >>

    >
    ><http://en.wikibooks.org/wiki/Java_Programming/Keywords/transient>


    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?


    --
    Paul Tomblin <> http://blog.xcski.com/
    Can't get out of 'vi'? Common problem. Don't worry, I'm here to help. Just
    log in as root and type "init 0". It works for pretty much any problem you
    might have with Linux. No, no, no. Thank /you/. -- Mikey Raeder
    Paul Tomblin, Jul 23, 2008
    #4
  5. Paul Tomblin

    Jeff Higgins Guest

    Jeff Higgins wrote:
    >
    > Jeff Higgins wrote:
    >>
    >> Paul Tomblin wrote:
    >>>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?
    >>>

    >>
    >> <http://en.wikibooks.org/wiki/Java_Programming/Keywords/transient>
    >>

    >
    > <http://en.wikipedia.org/wiki/Serialization#Java>
    >


    <http://findbugs.sourceforge.net/bugDescriptions.html>
    Jeff Higgins, Jul 23, 2008
    #5
  6. Paul Tomblin

    Jeff Higgins Guest

    Paul Tomblin wrote:
    > In a previous article, "Jeff Higgins" <> said:
    >>
    >>Paul Tomblin wrote:
    >>>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?
    >>>

    >>
    >><http://en.wikibooks.org/wiki/Java_Programming/Keywords/transient>

    >
    > 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
    Jeff Higgins, Jul 23, 2008
    #6
  7. Paul Tomblin

    Paul Tomblin Guest

    In a previous article, "Jeff Higgins" <> said:
    ><http://findbugs.sourceforge.net/bugDescriptions.html>


    Ah, that's very useful. Thanks.

    Turns out it's a crap warning - the default value is appropriate when it's
    been deserialized, and they're just warning me it might not be.


    --
    Paul Tomblin <> http://blog.xcski.com/
    "Our documented process says that I must now laugh in your face and double our
    price." - Dilbert's boss does ISO-9000
    Paul Tomblin, Jul 23, 2008
    #7
  8. Paul Tomblin

    Daniel Pitts Guest

    Paul Tomblin wrote:
    > In a previous article, "Jeff Higgins" <> said:
    >> Paul Tomblin wrote:
    >>> 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?
    >>>

    >> <http://en.wikibooks.org/wiki/Java_Programming/Keywords/transient>

    >
    > 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.

    --
    Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
    Daniel Pitts, Jul 25, 2008
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    347
  2.  opalinski from opalpaweb

    How to use Findbugs 1.1 (as compared to say .95)

    opalinski from opalpaweb, Oct 2, 2006, in forum: Java
    Replies:
    2
    Views:
    373
    opalinski from opalpaweb
    Oct 2, 2006
  3. comp.lang.java.programmer

    Remove a Category from findbugs?

    comp.lang.java.programmer, Feb 22, 2007, in forum: Java
    Replies:
    2
    Views:
    390
    comp.lang.java.programmer
    Feb 23, 2007
  4. findbugs for C/C++?

    , Mar 3, 2006, in forum: C++
    Replies:
    5
    Views:
    2,352
    Dietmar Kuehl
    Mar 5, 2006
  5. crazzybugger
    Replies:
    0
    Views:
    504
    crazzybugger
    Dec 21, 2007
Loading...

Share This Page