antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
17.19k stars 3.29k forks source link

Could not deserialize ATN with version 4 (expected 3). #3895

Open evan-zhangbo opened 2 years ago

evan-zhangbo commented 2 years ago

Details:

KvanTTT commented 2 years ago

You have to regenerate lexer or parser with the new ANTLR 4.10.1.

RayDean commented 1 year ago

same problem, any ideas?

tkrah commented 1 year ago

same problem, any ideas?

regenerate it with the new version or force the old (e.g. 4.9.3) version with (e.g. gradle):

    runtimeOnly("org.antlr:antlr4-runtime") {
        version {
            strictly '4.9.3'
        }
    }
kmcsekar commented 1 year ago

I have the same issue, How can I fix this on Maven POM. I have tried several options to exclude antlr and nothing helped. I need to pin antlr-runtime in my hibernate-core. Please let me know how to do that. Thanks!

Caused by: java.lang.UnsupportedOperationException: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 4 (expected 3). at org.antlr.v4.runtime.atn.ATNDeserializer.deserialize(ATNDeserializer.java:146) at org.hibernate.grammars.hql.HqlLexer.(HqlLexer.java:1387) ... 87 common frames omitted Caused by: java.io.InvalidClassException

cervenf commented 1 year ago

Hi, I had the same issue. I upgraded to 4.10. Then I deleted my generated code and seems to works so far.

SlawekGarwol commented 1 year ago

Using antlr4-maven-plugin (version 4.10+) and it generates _serializedATN witch cannot be deserialized

sgrs3093 commented 1 year ago

While migrating JDK 8 to JDK17 , Spring boot 2.x to SpringBoot 3.x , Spring framework from 5 to 6.. I got this issue in my local.

Caused by: java.lang.UnsupportedOperationException: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 4 (expected 3). at org.antlr.v4.runtime.atn.ATNDeserializer.deserialize(ATNDeserializer.java:187) at org.hibernate.grammars.hql.HqlLexer.(HqlLexer.java:1412) ... 64 more Caused by: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 4 (expected 3). ... 66 more

Could you please help me with this.. This is the dependency i am using currently ..along with Latest spring boot ,hibernate, jpa jars .

org.antlr antlr4 4.9.2
    <dependency>
        <groupId>org.antlr</groupId>
        <artifactId>antlr4-runtime</artifactId>
        <version>4.9.2</version>
    </dependency>
sgrs3093 commented 1 year ago

While migrating JDK 8 to JDK17 , Spring boot 2.x to SpringBoot 3.x , Spring framework from 5 to 6.. I got this issue in my local.

Caused by: java.lang.UnsupportedOperationException: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 4 (expected 3). at org.antlr.v4.runtime.atn.ATNDeserializer.deserialize(ATNDeserializer.java:187) at org.hibernate.grammars.hql.HqlLexer.(HqlLexer.java:1412) ... 64 more Caused by: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 4 (expected 3). ... 66 more

Could you please help me with this.. This is the dependency i am using currently ..along with Latest spring boot ,hibernate, jpa jars . org.antlr antlr4 4.9.2 org.antlr antlr4-runtime 4.9.2

Solution for my issue: I could able to resolve by commenting antlr jar from my pom.xml..As i had already generated parser and lexer class with my jdk 8 version part of my project..now when i am upgrading spring boot2.x to spring boot 3.x this issue was coming because i had excluded hibernate antlr compile time jar that also came with spring jpa. Hibernate required its own antlr jar at run time to parse the query etc, i had excluded that runtime antlr jar , that was giving the issue, so don't exclude antlr from hibernate side. This solves my issue.

bndeshpande commented 1 year ago

Solution for my issue: I could able to resolve by commenting antlr jar from my pom.xml..As i had already generated parser and lexer class with my jdk 8 version part of my project..now when i am upgrading spring boot2.x to spring boot 3.x this issue was coming because i had excluded hibernate antlr compile time jar that also came with spring jpa. Hibernate required its own antlr jar at run time to parse the query etc, i had excluded that runtime antlr jar , that was giving the issue, so don't exclude antlr from hibernate side. This solves my issue.

I don't have antlr4 in my pom.xml but still having issues. I have upgraded java 8 to java 17 and spring boot to 3.x

Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.UnsupportedOperationException: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 3 (expected 4).

Patrik1329 commented 1 year ago

by: java.lang.ExceptionInInitializerError: Exception java.lang.UnsupportedOperationException: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with

Hey @bndeshpande, Is this issue open for you? You comment starts with "Solution for my issue:", could you please let me know if you are facing this issue as well. As the title doesn't match with the description. I am assuming you still have this issue, please correct my asssumption.

Francesco146 commented 1 year ago

still an issue, there's not a workaround atm

KvanTTT commented 1 year ago

Doesn't parser regeneration with new generator help?

Francesco146 commented 1 year ago

not in my case, in my pom.xml i don't have any dependency linked to antlr, if i add it manually it changes only the runtime version of antlr, the version used in "code generation" is still the same... mvn clean install says version 4.13.1 is being used, but when i run the unit tests it says v4.10.1 for code generation, and v4.13.1 for runtime...

fidelisfelipe commented 1 year ago

+1 Spring Boot 3.5.1 + mssql-jdbc-12.4.1.jre11.

        at com.microsoft.sqlserver.jdbc.SQLServerFMTQuery.<init>(SQLServerFMTQuery.java:100) ~[mssql-jdbc-12.4.1.jre11.jar:na]
    at com.microsoft.sqlserver.jdbc.SQLServerParameterMetaData.<init>(SQLServerParameterMetaData.java:357) ~[mssql-jdbc-12.4.1.jre11.jar:na]
        ...
       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) ~[antlr4-runtime-4.10.1.jar:4.10.1]
    at org.antlr.v4.runtime.atn.ATNDeserializer.deserialize(ATNDeserializer.java:48) ~[antlr4-runtime-4.10.1.jar:4.10.1]
    at com.microsoft.sqlserver.jdbc.SQLServerLexer.<clinit>(SQLServerLexer.java:425) ~[mssql-jdbc-12.4.1.jre11.jar:na]
ericvergnaud commented 1 year ago

@KvanTTT I guess it's not a massive amount of work to support both v3 and v4 deserialization (like we do in C#, js and python) ? Is that something you could consider in order to reduce the "noise" ?

KvanTTT commented 1 year ago

It's a massive amount of work because it requires changing code of all targets and writing tests. Moreover, if it's supported, both versions (v3 and v4) should be maintained in future. It's a lot of effort without big benefit.

SlawekGarwol commented 1 year ago

Again. You need to fix your maven plugin. IT generates ATN in old version. I can test it again with new antlr version, but my last tests (reported here) shows it clearly. We use maven plug-in to generate classes based on grammar during the each build. Classes are not stored in git. We got runtime exception with the same version of antlr

pon., 23 paź 2023, 23:23 użytkownik Ivan Kochurkin @.***> napisał:

It's a massive amount of work because it requires changing code of all targets and writing tests. Moreover, if it's supported, both versions (v3 and v4) should be maintained in future. It's a lot of effort without big benefit.

— Reply to this email directly, view it on GitHub https://github.com/antlr/antlr4/issues/3895#issuecomment-1776043056, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABO7WDCNGTW6JRUENWGW4ATYA3N3NAVCNFSM6AAAAAAQSWXXYOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZWGA2DGMBVGY . You are receiving this because you commented.Message ID: @.***>

ericvergnaud commented 1 year ago

The plug-in version needs to match the runtime version. Have you tried 4.13.1 ?

weikangchia commented 1 year ago

Hi, I have the same issue. May I know if anyone has any solution?

frisbee7 commented 11 months ago

I stumbled upon this problem when I migrated our project from Spring Boot 2.7 -> Spring Boot 3.0. We didn't have any direct antlr dependencies in our pom.xml.

What helped me after reading this comment was to add this dependency to our pom.xml:

        <dependency>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4-runtime</artifactId>
            <version>4.9.3</version>
        </dependency>

Maybe it will help someone else too.