On Thu, 31 Aug 2023 08:02:35 GMT, Prasanta Sadhukhan <psadhuk...@openjdk.org> wrote:
> After the first time a JTableHeader is serialized, it no longer will > uninstall its UI upon subsequent serializations. > This happens for classes that use the BasicTableHeaderUI class. Any LAF that > extends the BasicTableHeaderUI like SynthTableHeaderUI and > WindowsTableHeaderUI will get an NotSerializableException thrown > > Each time an JComponent instance is Serialized, a [counter > ](https://github.com/openjdk/jdk/blob/218829e0a2a3ae5599b81733df53557966392033/src/java.desktop/share/classes/javax/swing/JComponent.java#L5644-L5645) > for the instance is incremented. It is de-incremented in JComponent's > writeObject or a class that implements it the same way, like JButton, > JScrollPane etc.. > With JTableHeader it does not deincrement the counter. The uninstall > mechanism will not uninstall a UI if the counter is not 0 on the first > pass..It is not possible to call JComponent.setWriteObjectCounter in > JTableHeader as it is not in the same package so the fix is to remove the > writeObject implementation and rely on JComponent writeObject implementation > to make sure uninstallation of UI happens and also NotSerializableException > does not happen for Synth Changes requested by aivanov (Reviewer). test/jdk/javax/swing/JTableHeader/SerializeJTableHeader.java line 44: > 42: JTableHeader jth = new JTableHeader(); > 43: try { > 44: for(int i = 0; i < 10; i ++){ Suggestion: for (int i = 0; i < 10; i ++) { test/jdk/javax/swing/JTableHeader/SerializeJTableHeader.java line 46: > 44: for(int i = 0; i < 10; i ++){ > 45: ByteArrayOutputStream baos = new ByteArrayOutputStream(); > 46: ObjectOutputStream oos = new ObjectOutputStream(baos); You should use try with resources to close the streams as a good pattern, even though closing byte-array does nothing, nor does it leak any resources. test/jdk/javax/swing/JTableHeader/SerializeJTableHeader.java line 54: > 52: catch (Exception x) { > 53: x.printStackTrace(); > 54: } Shouldn't the test fail if an exception is thrown? Without the fix, `NotSerializableException` is expected, and the test will fail. But the test will never fail if you catch the exception to print a message. Suggestion: } catch (Exception x) { x.printStackTrace(); } test/jdk/javax/swing/JTableHeader/SerializeJTableHeader.java line 68: > 66: } > 67: > 68: public static void main(String ... args) throws Exception{ Suggestion: public static void main(String... args) throws Exception { There's usually no space before the ellipses. ------------- PR Review: https://git.openjdk.org/jdk/pull/15507#pullrequestreview-1620659017 PR Review Comment: https://git.openjdk.org/jdk/pull/15507#discussion_r1321963036 PR Review Comment: https://git.openjdk.org/jdk/pull/15507#discussion_r1321964990 PR Review Comment: https://git.openjdk.org/jdk/pull/15507#discussion_r1321967563 PR Review Comment: https://git.openjdk.org/jdk/pull/15507#discussion_r1321968570