Review remaining diff between 9.0.x and 8.5.x and back-port remaining changes.
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc8.5.x/trunk@1821314 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/java/org/apache/tomcat/util/buf/ByteChunk.java b/java/org/apache/tomcat/util/buf/ByteChunk.java
index aa85a15..43d7cb0 100644
--- a/java/org/apache/tomcat/util/buf/ByteChunk.java
+++ b/java/org/apache/tomcat/util/buf/ByteChunk.java
@@ -17,6 +17,8 @@
 package org.apache.tomcat.util.buf;
 
 import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
 import java.nio.charset.Charset;
@@ -128,8 +130,9 @@
     // byte[]
     private byte[] buff;
 
-    private ByteInputChannel in = null;
-    private ByteOutputChannel out = null;
+    // transient as serialization is primarily for values via, e.g. JMX
+    private transient ByteInputChannel in = null;
+    private transient ByteOutputChannel out = null;
 
 
     /**
@@ -143,6 +146,19 @@
         allocate(initial, -1);
     }
 
+
+    private void writeObject(ObjectOutputStream oos) throws IOException {
+        oos.defaultWriteObject();
+        oos.writeUTF(getCharset().name());
+    }
+
+
+    private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
+        ois.defaultReadObject();
+        this.charset = Charset.forName(ois.readUTF());
+    }
+
+
     @Override
     public Object clone() throws CloneNotSupportedException {
         return super.clone();
@@ -699,6 +715,7 @@
         return (ret >= start) ? ret - start : -1;
     }
 
+
     /**
      * Returns the first instance of the given character in the given byte array
      * between the specified start and end. <br>
diff --git a/java/org/apache/tomcat/util/buf/CharChunk.java b/java/org/apache/tomcat/util/buf/CharChunk.java
index 19e4e89..7cd73e9 100644
--- a/java/org/apache/tomcat/util/buf/CharChunk.java
+++ b/java/org/apache/tomcat/util/buf/CharChunk.java
@@ -70,8 +70,9 @@
     // char[]
     private char[] buff;
 
-    private CharInputChannel in = null;
-    private CharOutputChannel out = null;
+    // transient as serialization is primarily for values via, e.g. JMX
+    private transient CharInputChannel in = null;
+    private transient CharOutputChannel out = null;
 
 
     /**