From ab4edcfaf8969b54994b6b9090eb47f1c51c0c46 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Wed, 1 Feb 2012 12:56:26 -0500 Subject: [PATCH] When serializing lists, convert to LinkedList ArrayList and emptyList() don't seem to serialize correctly on JDK 1.6.0 betas. Unknown which other JDKs are affected. Speculating that the problem is http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6446627 --- .../com/typesafe/config/impl/ConfigDelayedMerge.java | 11 +++++++++++ .../config/impl/ConfigDelayedMergeObject.java | 11 +++++++++++ .../com/typesafe/config/impl/ConfigSubstitution.java | 11 +++++++++++ .../com/typesafe/config/impl/SimpleConfigList.java | 11 +++++++++++ 4 files changed, 44 insertions(+) diff --git a/config/src/main/java/com/typesafe/config/impl/ConfigDelayedMerge.java b/config/src/main/java/com/typesafe/config/impl/ConfigDelayedMerge.java index 4cca7834..eafe8c52 100644 --- a/config/src/main/java/com/typesafe/config/impl/ConfigDelayedMerge.java +++ b/config/src/main/java/com/typesafe/config/impl/ConfigDelayedMerge.java @@ -3,6 +3,7 @@ */ package com.typesafe.config.impl; +import java.io.ObjectStreamException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -228,4 +229,14 @@ final class ConfigDelayedMerge extends AbstractConfigValue implements sb.append("# ) end of unresolved merge\n"); } } + + // This ridiculous hack is because some JDK versions apparently can't + // serialize an array, which is used to implement ArrayList and EmptyList. + // maybe + // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6446627 + private Object writeReplace() throws ObjectStreamException { + // switch to LinkedList + return new ConfigDelayedMerge(origin(), + new java.util.LinkedList(stack), ignoresFallbacks); + } } diff --git a/config/src/main/java/com/typesafe/config/impl/ConfigDelayedMergeObject.java b/config/src/main/java/com/typesafe/config/impl/ConfigDelayedMergeObject.java index fe970d59..0892975a 100644 --- a/config/src/main/java/com/typesafe/config/impl/ConfigDelayedMergeObject.java +++ b/config/src/main/java/com/typesafe/config/impl/ConfigDelayedMergeObject.java @@ -3,6 +3,7 @@ */ package com.typesafe.config.impl; +import java.io.ObjectStreamException; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -192,4 +193,14 @@ class ConfigDelayedMergeObject extends AbstractConfigObject implements protected AbstractConfigValue peek(String key) { throw notResolved(); } + + // This ridiculous hack is because some JDK versions apparently can't + // serialize an array, which is used to implement ArrayList and EmptyList. + // maybe + // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6446627 + private Object writeReplace() throws ObjectStreamException { + // switch to LinkedList + return new ConfigDelayedMergeObject(origin(), + new java.util.LinkedList(stack), ignoresFallbacks); + } } diff --git a/config/src/main/java/com/typesafe/config/impl/ConfigSubstitution.java b/config/src/main/java/com/typesafe/config/impl/ConfigSubstitution.java index 6fce27a8..a3620ca7 100644 --- a/config/src/main/java/com/typesafe/config/impl/ConfigSubstitution.java +++ b/config/src/main/java/com/typesafe/config/impl/ConfigSubstitution.java @@ -3,6 +3,7 @@ */ package com.typesafe.config.impl; +import java.io.ObjectStreamException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -284,4 +285,14 @@ final class ConfigSubstitution extends AbstractConfigValue implements } } } + + // This ridiculous hack is because some JDK versions apparently can't + // serialize an array, which is used to implement ArrayList and EmptyList. + // maybe + // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6446627 + private Object writeReplace() throws ObjectStreamException { + // switch to LinkedList + return new ConfigSubstitution(origin(), new java.util.LinkedList(pieces), + prefixLength, ignoresFallbacks); + } } diff --git a/config/src/main/java/com/typesafe/config/impl/SimpleConfigList.java b/config/src/main/java/com/typesafe/config/impl/SimpleConfigList.java index 01a644f0..381d3207 100644 --- a/config/src/main/java/com/typesafe/config/impl/SimpleConfigList.java +++ b/config/src/main/java/com/typesafe/config/impl/SimpleConfigList.java @@ -3,6 +3,7 @@ */ package com.typesafe.config.impl; +import java.io.ObjectStreamException; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -367,4 +368,14 @@ final class SimpleConfigList extends AbstractConfigValue implements ConfigList { protected SimpleConfigList newCopy(boolean ignoresFallbacks, ConfigOrigin newOrigin) { return new SimpleConfigList(newOrigin, value); } + + // This ridiculous hack is because some JDK versions apparently can't + // serialize an array, which is used to implement ArrayList and EmptyList. + // maybe + // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6446627 + private Object writeReplace() throws ObjectStreamException { + // switch to LinkedList + return new SimpleConfigList(origin(), new java.util.LinkedList(value), + resolveStatus()); + } }