1

Problem description

Swing components implement Serializable. There are some historical reasons as to why that is (see Meta section).

However apart from these reasons I vaguely remember having read about the JVM serializing JComponent objects and derivates for supposedly performance reasons(?) during runtime. This was stored firmly in my mind, after having read some source on this topic a while ago, however as I attempted to verify this I was unable to discover any sources stating something similar.

Questions

  • Does the JVM serialize / deserialize Swing components during runtime for performance reasons without explicitely calling for serialization programatically?
  • Is there a source describing this phenomenon?
  • If the JVM were to do that, is it then possible for standard serial UIDs (as opposed to generated ones) to cause runtime errors, when there is only one JVM and no explicit serialization / deserialization involved? Standard IDs have a form such as:
private static final long serialVersionUID = 1L;

As of now I am lead to believe that my memory is plain wrong. There is no mention of runtime serialization of JComponents in any of those sources. Can this be confirmed / rejected?

Meta

Related to this question:

Koenigsberg
  • 1,726
  • 1
  • 10
  • 22
  • I don't remember reading anything about that and I didn't experience that at all. If Swing would be doing this (automagically) then its probably just for the current JVM instance, i.e. it would not deserialize any "old" components. Thus serial version uid could be anything you want as there shouldn't be any version conflicts to worry about. – Thomas Dec 08 '20 at 14:50
  • I agree, especially *w.r.t* to the current JVM instance. However I am wondering if the current instance might encounter issues, when multiple classes share the default UID `1L`. A possible use case might be some type of caching. Though again, as mentioned, I am no longer able to find the source I got this idea from. – Koenigsberg Dec 08 '20 at 14:53
  • I didn't use Java serialization in years so my memory is a bit rusty but afaik the uid applies at the class level so multiple classes using the default uid should not be a problem. – Thomas Dec 08 '20 at 14:58
  • Ah yes, that makes sense. So even if the JVM was utlizing some type of caching using `JComponent` serialization, this is only relevant to potential runtime errors, when multiple JVMs are involved, as otherwise the JVM would have to somehow attempt to load two versions of the same class in one launch. Thank you for your insight so far. – Koenigsberg Dec 08 '20 at 15:05

0 Answers0