Unable to run Antlr 4.10 code on JDK 8

568 views
Skip to first unread message

Niels Basjes

unread,
Apr 14, 2022, 6:39:15 PM4/14/22
to antlr-discussion
Hi,

I updated my project (https://yauaa.basjes.nl) that uses Antlr to the 4.10 release today.
I usually build my software with JDK 17 and have the target set to JDK 8 so more people can use it. Note that I have shaded Antlr4 to a different package, hence the slightly different names in the stack trace below.

I found that when actually running the application on JDK 8 (I use docker to achieve this and really get Java 8) it fails with this:

java.lang.NoSuchMethodError: java.nio.CharBuffer.flip()Ljava/nio/CharBuffer;
    at nl.basjes.shaded.org.antlr.v4.runtime.CharStreams.fromString(CharStreams.java:227)
    at nl.basjes.shaded.org.antlr.v4.runtime.CharStreams.fromString(CharStreams.java:212)
    at nl.basjes.parse.useragent.analyze.MatcherAction.initialize(MatcherAction.java:152)
    at nl.basjes.parse.useragent.analyze.MatcherRequireAction.initialize(MatcherRequireAction.java:43)
    at nl.basjes.parse.useragent.analyze.Matcher.initialize(Matcher.java:200)
    at java.util.ArrayList.forEach(ArrayList.java:1259)

I did some digging and found this question which has the same problem:

Quote:

That's a very strange one. In Java 9, CharBuffer overrides the Buffer#flip method which returns a CharBuffer. In Java 8, it does override the method but the method still exists in the superclass Buffer but that one has a different return type than the class it was compiled against.

Please help.

Niels Basjes



Terence Parr

unread,
Apr 14, 2022, 6:51:12 PM4/14/22
to antlr-di...@googlegroups.com
Yes I was defeated by Maven. I need to generate a new release that specifies 1. 8 in a third location in the build file

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/antlr-discussion/82c2fe9c-fbfe-4efa-bab6-1a7e3a045426n%40googlegroups.com.
--
Dictation in use. Please excuse homophones, malapropisms, and nonsense.

Niels Basjes

unread,
Apr 15, 2022, 7:34:19 AM4/15/22
to antlr-discussion
Good to hear you have tracked it down already.
Any idea when you'll have this minor patch version released?

Niels

Op vrijdag 15 april 2022 om 00:51:12 UTC+2 schreef Terence Parr:

Niels Basjes

unread,
Apr 15, 2022, 7:40:12 AM4/15/22
to antlr-discussion
To add to the information available I found this page:
This mentions in addition to the release flag during the build that adding a cast to "Buffer" is also a way to mitigate this isssue.

Niels

Op vrijdag 15 april 2022 om 13:34:19 UTC+2 schreef Niels Basjes:

Terence Parr

unread,
Apr 15, 2022, 1:32:51 PM4/15/22
to antlr-di...@googlegroups.com
I will try to release this afternoon :)
Ter

Dictation in use. Please excuse homophones, malapropisms, and nonsense.


Niels Basjes

unread,
Apr 16, 2022, 4:51:42 PM4/16/22
to antlr-discussion
Thanks, the new version works perfectly.

Niels

Op vrijdag 15 april 2022 om 19:32:51 UTC+2 schreef Terence Parr:

Terence Parr

unread,
Apr 16, 2022, 5:19:58 PM4/16/22
to antlr-discussion
hooray!! Sorry for the mess up.  Trying to learn antlr again after 8 years haha

Roger Whitcomb

unread,
Jul 20, 2022, 12:17:37 PM7/20/22
to antlr-discussion
I just downloaded 4.10.1 from the downloads page here: https://www.antlr.org/download.html and I'm getting errors trying to generate my grammar using Java 8, and sure enough, "javap -v org.antlr.v4.Tool" shows class version 55 (Java 11).
So, is there any way to get the "antlr-4.10.1-complete.jar" completely built for Java 8?  Interestingly I see other classes in that .jar file have version 52 (such as org.stringtemplate.v4.DateRenderer).

Terence Parr

unread,
Jul 20, 2022, 12:54:04 PM7/20/22
to antlr-discussion
hi. The tool is requiring Java 11 now but the run time is still 8.
Ter

Roger Whitcomb

unread,
Jul 20, 2022, 7:14:26 PM7/20/22
to antlr-discussion
Got it working! Thanks.
Reply all
Reply to author
Forward
0 new messages