diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ATNDeserializer.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ATNDeserializer.java index 0bd643a131..95e37eaa09 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ATNDeserializer.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ATNDeserializer.java @@ -20,10 +20,10 @@ * @author Sam Harwell */ public class ATNDeserializer { - public static final int SERIALIZED_VERSION; - static { - SERIALIZED_VERSION = 4; - } + + static final int LEGACY_SERIALIZED_VERSION = 3; + + public static final int SERIALIZED_VERSION = 4; interface UnicodeDeserializer { // Wrapper for readInt() or readInt32() @@ -90,6 +90,12 @@ public ATN deserialize(char[] data) { int p = 0; int version = toInt(data[p++]); + if (version == LEGACY_SERIALIZED_VERSION) { + // Preserve backwards compatibility for version 3. We simply skip over the UUID and assume all + // features were supported. + p += 8; + version = SERIALIZED_VERSION; + } if (version != SERIALIZED_VERSION) { String reason = String.format(Locale.getDefault(), "Could not deserialize ATN with version %d (expected %d).", version, SERIALIZED_VERSION); throw new UnsupportedOperationException(new InvalidClassException(ATN.class.getName(), reason));