Skip to content

Commit 01bc811

Browse files
authored
[Java] Preserve serialized ATN version 3 compatibility (#3583)
1 parent e33ed11 commit 01bc811

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

runtime/Java/src/org/antlr/v4/runtime/atn/ATNDeserializer.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
* @author Sam Harwell
2121
*/
2222
public class ATNDeserializer {
23-
public static final int SERIALIZED_VERSION;
24-
static {
25-
SERIALIZED_VERSION = 4;
26-
}
23+
24+
static final int LEGACY_SERIALIZED_VERSION = 3;
25+
26+
public static final int SERIALIZED_VERSION = 4;
2727

2828
interface UnicodeDeserializer {
2929
// Wrapper for readInt() or readInt32()
@@ -90,6 +90,12 @@ public ATN deserialize(char[] data) {
9090

9191
int p = 0;
9292
int version = toInt(data[p++]);
93+
if (version == LEGACY_SERIALIZED_VERSION) {
94+
// Preserve backwards compatibility for version 3. We simply skip over the UUID and assume all
95+
// features were supported.
96+
p += 8;
97+
version = SERIALIZED_VERSION;
98+
}
9399
if (version != SERIALIZED_VERSION) {
94100
String reason = String.format(Locale.getDefault(), "Could not deserialize ATN with version %d (expected %d).", version, SERIALIZED_VERSION);
95101
throw new UnsupportedOperationException(new InvalidClassException(ATN.class.getName(), reason));

0 commit comments

Comments
 (0)