Parboiled under Java 21: Unsupported class file major version 65
Asked Answered
E

3

6

I'm am using parboiled as a dependency:

// https://mvnrepository.com/artifact/org.parboiled/parboiled-java
api 'org.parboiled:parboiled-java:1.4.1'

After updating from java 17 to 21 I am getting this error at runtime when trying to create a parser:

java.lang.RuntimeException: Error creating extended parser class: Unsupported class file major version 65
        at org.parboiled.Parboiled.createParser(Parboiled.java:58)

Version 65 class files is Java 21. The parser class is now indeed compiled with target 21. Why would parboiled not work with it? Any other workarounds outside of downgrading to target 17?

Minimal reproducible example:

build.gradle

plugins {
    id "application"
}
apply plugin : "java" 

ext {
   javaMainClass = "test.TestParser"
}

application {
    mainClassName = javaMainClass
}
dependencies {
    
    implementation 'org.parboiled:parboiled-java:1.4.1'
}

TestParser.java

package test;

import org.parboiled.BaseParser;
import org.parboiled.Parboiled;
import org.parboiled.Rule;
import org.parboiled.annotations.BuildParseTree;


@BuildParseTree
public class TestParser extends BaseParser<Object> {
    
    public Rule InputLine() {
        return Sequence(Digit(), EOI);
    }
    Rule Digit() {
        return CharRange('0', '9');
    }

    
    public static void main(String[] args) {
        TestParser parser = Parboiled.createParser(TestParser.class);
    }

}

gradle run

Configuration on demand is an incubating feature.
> Task :test2:compileJava
> Task :test2:processResources NO-SOURCE
> Task :test2:classes

> Task :test2:run FAILED
Exception in thread "main" java.lang.RuntimeException: Error creating extended parser class: Unsupported class file major version 65
        at org.parboiled.Parboiled.createParser(Parboiled.java:58)
        at test.TestParser.main(TestParser.java:34)
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 65
        at org.objectweb.asm.ClassReader.<init>(ClassReader.java:199)
        at org.objectweb.asm.ClassReader.<init>(ClassReader.java:180)
        at org.objectweb.asm.ClassReader.<init>(ClassReader.java:166)
        at org.objectweb.asm.ClassReader.<init>(ClassReader.java:287)
        at org.parboiled.transform.AsmUtils.createClassReader(AsmUtils.java:59)
        at org.parboiled.transform.ClassNodeInitializer.process(ClassNodeInitializer.java:62)
        at org.parboiled.transform.ParserTransformer.extendParserClass(ParserTransformer.java:44)
        at org.parboiled.transform.ParserTransformer.transformParser(ParserTransformer.java:39)
        at org.parboiled.Parboiled.createParser(Parboiled.java:54)
        ... 1 more
Endopeptidase answered 24/9, 2023 at 0:56 Comment(3)
Can you provide a minimal reproducible example? This smells like Java 17 may still be somewhere in your runtime environment; a Dockerfile, Nix derivation, or other self-contained reproducer would allow that possibility to be eliminated.Rothko
This doesn't seem like an environment problem to me. Parboiled has the ASM bytecode library as a dependency. Try upgrading that to version 9.5 for Java 21 support. A few more stack frames from the exception may be helpful though. Gradle version overriding: docs.gradle.org/current/userguide/dependency_constraints.htmlBidding
Forcing ASM 9.5 does indeed resolve the problem! parboiled-java:1.4.1 by default depends on 9.2.Endopeptidase
E
7

This failure is in the ASM library, which Parboiled has as a dependency. Parboiled 1.4.1 uses ASM 9.2, but Java 21 support was added in ASM 9.5.

Adding the following will force gradle to resolve all ASM dependencies to version 9.5 which resolves the problem:

configurations.all {
    resolutionStrategy.eachDependency { details ->
        if (details.requested.group == 'org.ow2.asm') {
            details.useVersion "9.5"
        }
    }
}
dependencies {
    implementation 'org.parboiled:parboiled-java:1.4.1'
}
Endopeptidase answered 24/9, 2023 at 1:36 Comment(0)
S
0

I have a workaround, but I don't know why it works. I am using Gradle 8.5 and am specifying

org.gradle.java.home=/Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home 

in my gradle.properties file. Whenever I introduce a new JAR (for example RDF4J), I get something like the following compilation error:

startup failed:
General error during conversion: Unsupported class file major version 65

java.lang.IllegalArgumentException: Unsupported class file major version 65
at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:199)
at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:180)
at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:166)
at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:287)
at org.codehaus.groovy.ast.decompiled.AsmDecompiler.parseClass(AsmDecompiler.java:81)
at org.codehaus.groovy.control.ClassNodeResolver.findDecompiled(ClassNodeResolver.java:251)
at org.codehaus.groovy.control.ClassNodeResolver.tryAsLoaderClassOrScript(ClassNodeResolver.java:189)
at org.codehaus.groovy.control.ClassNodeResolver.findClassNode(ClassNodeResolver.java:169)
at org.codehaus.groovy.control.ClassNodeResolver.resolveName(ClassNodeResolver.java:125)
at org.codehaus.groovy.ast.decompiled.AsmReferenceResolver.resolveClassNullable(AsmReferenceResolver.java:57)
at org.codehaus.groovy.ast.decompiled.AsmReferenceResolver.resolveClass(AsmReferenceResolver.java:44)
at org.codehaus.groovy.ast.decompiled.TypeSignatureParser.visitEnd(TypeSignatureParser.java:110)
...

If I:

  1. comment out the Java 21 line in my gradle.properties file
  2. compile with, for example, JavaSE-17

I get no errors. The thing I don't understand is if I then:

  1. clean the build
  2. uncomment the Java 21 line
  3. compile

Everything is fine.

September answered 7/2 at 15:30 Comment(0)
B
0

I changed to sdk1.8 and solved the problem

Banded answered 10/9 at 9:21 Comment(1)
Your solution is to downgrade the JDK?Haile

© 2022 - 2024 — McMap. All rights reserved.