WPI crashes when the sealed/non-sealed keywords are encountered
sealed and non-sealed are valid Java keywords in Java 17. However, WPI crashes when it encounters these keywords, as demonstrated by the following test, borrowed from the Java documentation (which is checked in on this branch):
// @below-java17-jdk-skip-test
// from https://docs.oracle.com/en/java/javase/15/language/sealed-classes-and-interfaces.html
public sealed class Figure
// The permits clause has been omitted
// as its permitted classes have been
// defined in the same file.
{}
final class Circle extends Figure {
float radius;
}
non-sealed class Square extends Figure {
float side;
}
sealed class Rectangle extends Figure {
float length, width;
}
final class FilledRectangle extends Rectangle {
int red, green, blue;
}
The stack trace is the following:
Problem stacktrace :
com.github.javaparser.GeneratedJavaParser.generateParseException(GeneratedJavaParser.java:14094)
com.github.javaparser.GeneratedJavaParser.jj_consume_token(GeneratedJavaParser.java:13939)
com.github.javaparser.GeneratedJavaParser.CompilationUnit(GeneratedJavaParser.java:405)
com.github.javaparser.JavaParser.parse(JavaParser.java:127)
com.github.javaparser.JavaParser.parse(JavaParser.java:242)
org.checkerframework.framework.util.JavaParserUtil.parseCompilationUnit(JavaParserUtil.java:88)
org.checkerframework.common.wholeprograminference.WholeProgramInferenceJavaParserStorage.addSourceFile(WholeProgramInferenceJavaParserStorage.java:511)
org.checkerframework.common.wholeprograminference.WholeProgramInferenceJavaParserStorage.addClassTree(WholeProgramInferenceJavaParserStorage.java:490)
org.checkerframework.common.wholeprograminference.WholeProgramInferenceJavaParserStorage.preprocessClassTree(WholeProgramInferenceJavaParserStorage.java:466)
org.checkerframework.common.wholeprograminference.WholeProgramInferenceImplementation.preprocessClassTree(WholeProgramInferenceImplementation.java:987)
org.checkerframework.framework.type.AnnotatedTypeFactory.setRoot(AnnotatedTypeFactory.java:859)
org.checkerframework.framework.type.GenericAnnotatedTypeFactory.setRoot(GenericAnnotatedTypeFactory.java:429)
...
This is pretty clearly a problem with JavaParser, which doesn't support features introduced in Java 14 or later (sealed and non-sealed were introduced in Java 15). However, I don't think WPI should crash in these cases: it would be better to e.g. not generate a .ajava file.
@mernst I think this is yet another reason to move away from JavaParser for parsing .ajava files, if you're still pursuing that. We encountered this when trying to run WPI on https://github.com/eponymouse/columnal, which requires Java 17 to build and extensively uses Java 17 features - it was also impacted by the fix in #5542, whose application lead to the discovery of this problem.
I looked into adding sealed and non-sealed to JavaParser (which is supposed to support up through Java 15). This is doable, but it's a lot of plumbing and I think switching the implementation approach is a better use of my time. So I'm not going to fix this issue by fixing JavaParser.
I think this should be closed? JavaParser now supports these keywords
This issue can be closed when we update Stubparser to a newer JavaParser. JavaParser 3.26.0 is too buggy to use. Maybe JavaParser 3.26.1 fixes enough bugs.