Java User Group - Warnings clean-up hack day - 31st of Jan

Martijn Verburg martijnverburg at gmail.com
Wed Feb 1 08:36:30 PST 2012


Hi Stuart,

Thanks very much again for helping out on the day, it certainly saved
a few of the devs
from getting permanently stuck!

> Ah, it looks like you guys wrapped up while I was taking my lunch break. I
> hope your hack session was fun and productive.

It was!  Mike (Michael Barker) is gathering together all of the
patches and will submit them
as we did last time.  We've spent a fair amount of time on the reviews
and so hopefully
they'll meet the quality bar.

With an improved VM and a better handle on what was fair game it
certainly went a lot
more quickly this time.

> There was a question on IRC about the serialization warnings. There's some
> additional information I wanted to add, so I'll post it here for everyone's
> benefit.
>
> --
>
> The compiler will occasionally issue warnings of the form: "warning:
> [serial] serializable class Foo has no definition of serialVersionUID".
> Usually the fix is to add a static serialVersionUID field initialized to the
> proper value.
>
> To get the proper serial version UID value, run the "serialver" tool using a
> *released* version of the JDK:
>
> $ serialver java.misc.Foo
> java.misc.Foo:    static final long serialVersionUID = 362498820763181265L;
>
> Paste this line into Foo.java, with the addition of the "private" modifier:
>
>    private static final long serialVersionUID = 362498820763181265L;
>
> Note however that anonymous inner classes should *not* have a
> serialVersionUID. Instead, use @SuppressWarnings("serial") to suppress the
> serialization warning for this case. We probably need to fix the compiler so
> that it doesn't issue warnings for these cases.
>
> (For the curious, the reason that anonymous inner classes shouldn't have a
> serialVersionUID is that serializing them might or might not work and that
> it's not possible to guarantee serialization compatibility for them. An
> anonymous inner class -- actually any inner class or non-static nested class
> -- has a reference to an "enclosing instance" of the class within which the
> inner class is defined. If the enclosing class isn't serializable,
> serialization of the inner instance will fail. Also, even if it were
> serializable, serializing the enclosing instance is probably not what you
> want. In addition, anonymous classes have names that are synthesized by the
> compiler, and these names may vary across compilers and may differ even from
> one build to the next, and class names must match for deserialization to
> succeed. Since the purpose of serialVersionUID is to help with serialization
> compatibility, including it in anonymous classes is pointless.)

Ah, excellent, I'm going to add that to the global notes I'm writing
up. Where I can
I'll try to add stuff the OpenJDK wiki and reference into there from
the JUG java.net
wiki that we have for this javac warning mini-programme.

Cheers,
Martijn


More information about the jdk8-dev mailing list