Skip to content

Commit

Permalink
[Java] Preserve serialized ATN version 3 compatibility (#3583)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcking authored Mar 14, 2022
1 parent e33ed11 commit 01bc811
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions runtime/Java/src/org/antlr/v4/runtime/atn/ATNDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 01bc811

Please sign in to comment.