我正在使用parboiled作为一个依赖项。
从Java 17更新到21后,当我尝试创建解析器时,运行时出现了以下错误:
// https://mvnrepository.com/artifact/org.parboiled/parboiled-java
api 'org.parboiled:parboiled-java:1.4.1'
从Java 17更新到21后,当我尝试创建解析器时,运行时出现了以下错误:
java.lang.RuntimeException: Error creating extended parser class: Unsupported class file major version 65
at org.parboiled.Parboiled.createParser(Parboiled.java:58)
版本65的类文件是Java 21。解析器类现在确实是使用目标21进行编译的。为什么parboiled不能与之一起工作?除了降级到目标17之外,还有其他解决方法吗?
最小可复现示例:
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