antlr / antlr/antlr4

ANTLR Tool version 4.4 used for code generation does not match the current runtime version 4.11.1

Open
#4,100 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
19k
Forks
3.5k
PR merge metrics
No merged PRs in 30d

Description

Version: `ANTLR4 Java`
OS: `Windows 11 Pro 64bit`

ANTLR Tool version 4.4 used for code generation does not match the current runtime version 4.11.1
Exception in thread "main" java.lang.ExceptionInInitializerError
at main.horizon.main(horizon.java:22)
Caused by: java.lang.UnsupportedOperationException: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 3 (expected 4).
at org.antlr.v4.runtime.atn.ATNDeserializer.deserialize(ATNDeserializer.java:56)
at org.antlr.v4.runtime.atn.ATNDeserializer.deserialize(ATNDeserializer.java:48)
at target.generatedsources.antlr4.horizonLexer.(horizonLexer.java:188)
... 1 more
Caused by: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 3 (expected 4).
... 4 more

Main class code:
```java
package main;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;

import target.generatedsources.antlr4.horizonLexer;
import target.generatedsources.antlr4.horizonParser;

public class horizon {
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a horizon file: ");
String fileName = scanner.next();
File temp = new File(fileName);
if (temp.exists()) {
CharStream charStream = CharStreams.fromFileName(fileName);
horizonLexer lexer = new horizonLexer(charStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
horizonParser parser = new horizonParser(commonTokenStream);
} else {
System.out.println("The file \"" + fileName + "\" doesn't exist!");
System.exit(1);
}
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the reported failure at horizon.java:22 and the generated target.generatedsources.antlr4.horizonLexer initializer. Check how ANTLR Tool 4.4 and runtime 4.11.1 are selected, then reproduce the ATN deserialization error with the supplied main class. Done means the generated lexer and runtime use compatible versions and the exception no longer occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.