JDK-8036568 : Serial incompatibility in java.util.TreeMap.NavigableSubMap
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 8,9
  • Priority: P1
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2014-03-04
  • Updated: 2014-07-17
  • Resolved: 2014-03-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u11Fixed 9 b04Fixed
Related Reports
Relates :  
Relates :  
Description
The enhancements done under JDK-8011426 in JDK 8 made some seemingly innocuous changes to the nested serialiable class java.util.TreeMap.NavigableSubMap. The JDK 6 era methods on TreeMap, including subMap, headMap, tailMap, descendingMap, return one or the other subclass of NavigableSubMap.

Unfortunately, NavigableSubMap did *not* have a serialVersionUID declared so the methods added under JDK-8011426 perturbed the serial hash computation for NavigableSubMap. As a result, while the subclasses of NavigableSubMap do declare serialVersionUIDs themselves, instances of the subclasses cannot be serialized in JDK 6 and successfully reconstituted in JDK 8, or vice versa.


Comments
Verified by SerialTest mentioned in bug. Serialization with jdk7 and deserialization with jdk9/b04 (and vice versa), pass; deserialization with jdk9/b02 (build before the fix) fail with java.io.InvalidClassException
01-04-2014

ILW=HMH -> P1 (High Impact, Medium Likelyhood, No easy workaround)
10-03-2014

@Joe, Correct, we would need a known issue that is only for JDK 8 GA, and then a release note for 8u5 that states that it's been addressed.
10-03-2014

the recent nighlty results for the binaries with the fix didn't show any issues that could be caused by the fix. SQE OK to take the fix into CPU14_02.
07-03-2014

// The following program can be used to create a result from TreeMap that cannot be serialized across versions: import java.io.*; import java.util.*; public class SerialTest { public static void main(String... args) throws Exception { if (args.length == 1) { writeSerialStream(); } else { readSerialStream(); } } static void writeSerialStream() throws IOException { TreeMap<String, String> treeMap = new TreeMap<String, String>(); treeMap.put("a", "A"); treeMap.put("b", "B"); treeMap.put("c", "C"); NavigableMap<String, String> nav = treeMap.headMap("b", true); System.out.println(nav.toString()); FileOutputStream fos = new FileOutputStream("navser"); try { ObjectOutputStream oos = new ObjectOutputStream(fos); try { System.out.println("Writing serial stream"); oos.writeObject(nav); } finally { oos.close(); } } finally { fos.close(); } } static void readSerialStream() throws IOException, ClassNotFoundException { Object serialResult; FileInputStream fis = new FileInputStream("navser"); try { ObjectInputStream ois = new ObjectInputStream(fis); try { System.out.println("Reading serial stream"); serialResult = ois.readObject(); } finally { ois.close(); } } finally { fis.close(); } System.out.println(serialResult.toString()); } } // The resulting file can be written and read by JDK 6 or 7 (in either role), but inter operating between {6, 7} and {8, 9} throws a java.io.InvalidClassException.
04-03-2014

The fix for this issue is to add a serialVersionUID to NavigableMap matching the serialver value from JDK 6 and 7.
04-03-2014