On Thu, 11 Dec 2025 04:45:41 GMT, Prasanta Sadhukhan <[email protected]> 
wrote:

>> Issue is when JTable is in editing mode, it is not Serializable as it gives 
>> exception
>> 
>> java.io.NotSerializableException: java.lang.reflect.Constructor
>>         at 
>> java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1149) at 
>> java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1502)
>>         at 
>> java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1467)
>>         at 
>> java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1385)
>>         at 
>> java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1143) at 
>> java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1502)
>> .......
>> 
>> 
>> It is caused by creation of `GenericEditor` class which uses a 
>> non-serializable Constructor field.
>> This is fixed by making the field transient..
>> Also, `editorRemover` field is made transient as it is object of 
>> `CellEditorRemover` class which is not Serializable..
>
> Prasanta Sadhukhan has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   GenericEditor serialization fix

So, as I see it is mentioned
`an instance of a static nested class (which is in this case GenericEditor) 
would be serialized along with the outer class instance is if the outer class 
instance holds an explicit reference to an instance of that static nested class 
as one of its fields`,
but no such explicit reference exists as far I can see.
The stacktrace shows the exception comes from 
 `at 
java.desktop/javax.swing.event.EventListenerList.writeObject(EventListenerList.java:286)`
but even making `EventListenerList `transient in `AbstractCellEditor `and 
`RowSorter `which are referenced in JTable, doesn't help

Also, as per this stackoverflow 
https://stackoverflow.com/questions/19282817/why-do-jtables-make-tablemodels-non-serializable-when-rendered
it is told "when you add a TableModelListener to an AbstractTableModel 
implementation, another listener is added in addition to the one you added, of 
type javax.swing.event.TableModelListener which isn't serializable" but I could 
not see how and also  following the same "workaround" of removing 
TableModelListener before serialization and adding it back, doesn't help
so if anyone has any idea of how to find the reference which is causing 
GenericEditor to be serialized, please let me know

-------------

PR Comment: https://git.openjdk.org/jdk/pull/28627#issuecomment-3644723007

Reply via email to