This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 19915 - Display warning when serializing instances of classes which do not declare serialVersionUID
Summary: Display warning when serializing instances of classes which do not declare se...
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 3.x
Hardware: All All
: P1 blocker (vote)
Assignee: _ ttran
URL:
Keywords:
: 19483 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-01-29 21:11 UTC by _ ttran
Modified: 2008-12-22 23:49 UTC (History)
6 users (show)

See Also:
Issue Type: TASK
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description _ ttran 2002-01-29 21:11:06 UTC
If serialVersionUID is not declared (defined) then serialized copy of class 
instance is likely not deserializable when the author of the class changes the 
code.  This is a common programmer mistake.  We can check for serialVersionUID 
at runtime and display an error message (or send warning into log file) when 
such a situation is detected.

See issue 19538 for more discussion.
Comment 1 _ ttran 2002-01-29 21:16:32 UTC
Also see issue 19483 for more thoughts.
Comment 2 _ ttran 2002-01-29 21:22:45 UTC
*** Issue 19483 has been marked as a duplicate of this issue. ***
Comment 3 Jaroslav Tulach 2002-01-30 09:04:45 UTC
Runtime check!? That will slow down the serialization, should not the
check be build-time?
Comment 4 _ ttran 2002-01-30 09:38:40 UTC
when you serialize instances you usually (at least in our context) you
must subsequently do some I/O operations which are *much* slower than
CPU.  So I do not care that much if the performance degradation does
not take 10 minutes.

Of course we need to do some measurements to get the hard numbers.
Comment 5 Jan Chalupa 2002-01-30 14:57:00 UTC
Not sure about the runtime check overhead, but it seems to me that the
infrastructure implemented by Milan Kubec could be used at build-time.
It is a kind of post-build checking task similar to the API signature
tests.
Comment 6 _ ttran 2002-01-30 15:30:04 UTC
Implemented in CVS trunk (NB 3.4) (I've stolen a piece of code from
Milan :-).  The warning output is er___ interesting.  Even some
anonymous inner classes are serialized, which is of course double evil.

The check is done in NbObjectOutputStream which I hope is used for all
serialization needs in NB.  Petr Nejedly, can you please check the
performance impact?  I believe there is virtually none, because we
should not touch the hard disk during time sensitive periods anyway. 
The diff is

http://openide.netbeans.org/source/browse/openide/src/org/openide/util/io/NbObjectOutputStream.java.diff?r1=1.14&r2=1.15

Comment 7 Jaroslav Tulach 2002-02-05 17:25:39 UTC
Jesse suggests to warn also about abstract instances:
http://www.netbeans.org/servlets/ReadMsg?msgId=253190&listName=nbdev
because if serializing class that has a superclass without SUID we can
get into similar problems as well...
Comment 8 Jesse Glick 2002-02-06 12:10:42 UTC
Trung please check, but I think your patch already does this fine -
AFAIK annotateClass is called with the superclass by the object stream
anyway.
Comment 9 Jaroslav Tulach 2002-02-13 14:37:27 UTC
Btw. after the issue 17164 has been implemented the serialVersionUID
is not a stopper for loading old version of classes. Its check can be
suppressed.

That might indicated that the check implemented as part of this issue
can be deleted.
Comment 10 _ ttran 2002-02-20 10:35:17 UTC
#17164 is useless for people who are switching between JDK 1.3 and JDK
1.4 (myself included).  For this reason forgetting to declare svuid is
still a showstopper.  Quoted from
http://java.sun.com/j2se/1.4/compatibility.html

---8<---
* If a serializable inner class contains explicit references to to its
class object, then the computed value of the serial version UID for
the class will be different in J2SE 1.3 and J2SE 1.4. The difference
is due to the fact that the computation of the serial version UID is
sensitive to modifications made in the javac compiler between J2SDK
1.3 and J2SDK 1.4.

To avoid this problem affecting your applications, we recommend that
you add an explicit serial version UID to your serializable classes.
You can use the serialver tool to obtain the serial version UID of
classes compiled with the J2SDK 1.3 javac compiler.

---8<--- end of quote --8<--
Comment 11 Jaroslav Tulach 2002-02-20 11:45:54 UTC
Trung you misunderstand. Issue 17164 is solution for this problem -
nevertheless what the JDK documentation says.
Comment 12 _ ttran 2002-02-20 12:02:44 UTC
I've reread the description of this issue and the solution described
in issue 17164 and cannot see how the latter can makes the former
obsolete.  Specifically I disagree with Yarda's statement

> That might indicated that the check implemented as part of this issue
> can be deleted.

Comment 13 _ ttran 2002-04-10 14:48:26 UTC
x
Comment 14 Jan Zajicek 2002-04-12 13:52:29 UTC
x verified
Comment 15 Jaroslav Tulach 2002-09-17 08:07:58 UTC
This issues prints warning every shutdown due to java.util.TreeSet.
Please exclude the TreeSet from the check.
Comment 16 Jesse Glick 2002-09-20 03:25:00 UTC
No! This warning *should* be there. See issue #21781.
Comment 17 Jaroslav Tulach 2002-09-20 09:07:10 UTC
No, no. Issue 21781 is completely invalid and should be wontfix, the
TreeSet should be removed from the check and a bug (more enhancement)
for the JDK team should be fired ensure that they will either add the
serialVersionUID to the TreeSet or keep the computed UID the same. Do
we think they do not have backward serialization compatibility tests?
Comment 18 Jan Chalupa 2002-09-20 09:27:29 UTC
IMO, no module should be serializing TreeSet directly and depending on
its serialization format. Usage of TreeSet is an internal
implementation detail. For the purpose of persistence, it should be
translated into a simpler, JDK-independent form. Issue 21781 should be
taken seriously.
Comment 19 Jaroslav Tulach 2002-09-20 10:14:18 UTC
Jan, are you talking about the future vision or current state? If the
later, then you should also say that no module should serialize
HashMap, ArrayList, Vector and all those other classes that we do
serialize. Your comment can be easily applied to any other utility
class not just TreeSet. I think it is ok to have your opinion for the
future vision, but it has to be understood that usage of TreeSet is
not worse than usage of ArrayList, which nobody complained about yet.
Comment 20 Jan Chalupa 2002-09-20 11:20:14 UTC
I'm talking about the vision we should have adopted and implemented
long time ago.

And yes, I think that using serialized instances of utility classes
for the purposes long-term persistence is evil. This includes
ArrayList, Vector, Hashtable, HashMap, String, (name your Java class).
And it really doesn't matter whether the serialization format is
native Java serialization or XML. The bad thing is that internal
implementation details get exposed where they shouldn't be.

I know my proposal sounds too radical, given the current
implementation, but I really think we should be moving in that direction.
Comment 21 Jaroslav Tulach 2002-09-20 13:31:56 UTC
Ok, I suggest to create another issue for vision things and dedicate
this one just to what is written in its summary.
Comment 22 Jan Chalupa 2002-09-20 15:33:15 UTC
Good point. See issue 27484.