[ https://issues.apache.org/jira/browse/WICKET-6644?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16791443#comment-16791443 ]
Thomas Heigl edited comment on WICKET-6644 at 3/13/19 8:42 AM: --------------------------------------------------------------- Should I create a PR for this? Which option do you prefer? Initialize the field to {{-1}} or change it to a {{Long}}? This is the code in question: {code:java} public abstract class AbstractPageableView<T> extends RefreshingView<T> implements IPageableItems { /** * <code>cachedItemCount</code> is used to cache the call to <code>internalGetItemCount()</code> * for the duration of the request because that call can potentially be expensive ( a select * count query ) and so we do not want to execute it multiple times. */ private transient long cachedItemCount; private void clearCachedItemCount() { cachedItemCount = -1; } private void setCachedItemCount(long itemCount) { cachedItemCount = itemCount; } private long getCachedItemCount() { if (cachedItemCount < 0) { throw new IllegalStateException("getItemCountCache() called when cache was not set"); } return cachedItemCount; } private boolean isItemCountCached() { return cachedItemCount >= 0; } private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { // Read in all fields s.defaultReadObject(); clearCachedItemCount(); } }{code} was (Author: thomas.heigl): Should I create a PR for this? Which option do you prefer? Initialize the field to {{-1}} or change it to a {{Long}}? This is the code in question: {code:java} public abstract class AbstractPageableView<T> extends RefreshingView<T> implements IPageableItems { /** * <code>cachedItemCount</code> is used to cache the call to <code>internalGetItemCount()</code> * for the duration of the request because that call can potentially be expensive ( a select * count query ) and so we do not want to execute it multiple times. */ private transient long cachedItemCount; private void clearCachedItemCount() { cachedItemCount = -1; } private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { // Read in all fields s.defaultReadObject(); clearCachedItemCount(); } }{code} > AbstractPageableView can only be serialized with Java built-in serialization > ---------------------------------------------------------------------------- > > Key: WICKET-6644 > URL: https://issues.apache.org/jira/browse/WICKET-6644 > Project: Wicket > Issue Type: Improvement > Components: wicket-core > Affects Versions: 8.3.0 > Reporter: Thomas Heigl > Priority: Major > > I'm in the progress of replacing FST serialization, that we have used in > production for years, with Kryo. > FST is a drop-in replacement for Java's built-in serialization and respects > the {{readObject/writeObject}} contract. Kryo does not rely on Java > serialization at all. > All of Wicket's classes can be serialized with recent versions of Kryo > without problems, but when I did some exploratory testing, I noticed that all > our pageable lists were empty after deserialization. > After some investigation, I found the root cause of this: WICKET-1323 > {{AbstractPageableView}} is the *only* class in Wicket that relies a custom > {{readObject}} method to correctly restore its state. > I propose to get rid of this method and simply initialize the transient field > to a default value of {{-1}} or use a {{Long}} instead of a {{long}} to > represent the cached item count. -- This message was sent by Atlassian JIRA (v7.6.3#76005)