Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[wtp-dev] Source Quality 2: serialVersionUID -- please don't make me fix these too


Another common problem that causes warnings in our source code is failure to declare a serialVersionUID for
a serializable class.

The full warning looks like this:
The serializable class DoubleObjectPrivilegeImpl does not declare a static final serialVersionUID field of type long

This generates about 150 warnings in about 15 projects.

Technically, classes which are serializable really should declare this static field since if that class ever was serialized, then any
future (or coexisting) versions might have to know the serialVersionUID to be able to deserialize it correctly.

Granted, this is the kind of warning that *might* never be a problem, as many classes are serializable for trivial reasons,
and would never be appropriate to actually serialize them .... but that is the 'contract' of serialization! (And, often you'd never really
know it was a problem until that future version existed, or someone started doing something over a network,
with different VM's on each end! ... which is, I suspect why its often overlooked, and why they give a warning).

My main concern is that we have so many of them, it makes it hard to see any "real" warnings.

And the cure is so easy .... just use QuickFix to add "default" versions.

          /**
         * Default <code>serialVersionUID</code>
         */
        private static final long serialVersionUID = 1L;

(I think you'd only have to use the "generate" version of the quick fix if you really had some concrete reason to, such as you
had existing serialized versions you were trying to retrofit).

I know many of these come from EMF generated classes. Is this an issue? Something that EMF needs to address better?

Thanks (either for fixing, or explaining why it can not or should not).

Remember, our goal is zero warnings during our builds.


Back to the top