Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java] Preserve serialized ATN version 3 compatibility #3583

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unclear what exacly LEGACY_SERIALIZED_VERSION is. What if SERIALIZED_VERSION will be incremented?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a loose patch to solve an internal problem we have.


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;
}
Comment on lines +93 to +98
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use tabs instead of spaces (ANTLR uses tabs formatting).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah,I am abandoning backward compatibility except for the java target because we have special internal problem to resolve. I'll deal with this when I can look at the 32 bit implementation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess I will do a bit of copy and paste programming for java if I get the 32-bit deserialization going. thanks for pointing this out

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