Skip to content

Cryptic parsing error messages with --link-at-build-time and incomplete classpath #6253

Closed
@zakkak

Description

@zakkak

Describe the issue
Parsing errors may be cryptic when using --link-at-build-time and incomplete classpath.
For instance if a Class A cannot be initialized due to a NoClassDefFoundError caused by a missing dependency, the user will be presented with an UnresolvedElementException stating that some method of Class A is unresolved, but it won't provide any additional info on the cause.

Steps to reproduce the issue

cd /tmp
git clone --branch 2023-03-21-graal-4661-parsing-error https://github.com/zakkak/issue-reproducers reproducer
cd reproducer
mvn package
export JAVA_HOME=/path/to/graalvm
# Attempt to generate native-image
$JAVA_HOME/bin/native-image \
  --no-fallback \
  -H:+ReportExceptionStackTraces \
  --link-at-build-time \
  --initialize-at-build-time=. \
  -jar target/reproducer-1.0-SNAPSHOT.jar

Describe GraalVM and your environment:

  • GraalVM version (latest snapshot builds can be found here), or commit id if built from source: e9893c0
  • JDK major version: 20
  • OS: Fedora 37
  • Architecture: AMD64

More details

The reproducer will result in build errors like the following:

Error: Unsupported features in 2 methods
Detailed message:
Error: Discovered unresolved method during parsing: net.sf.oval.expression.ExpressionLanguageJavaScriptImpl.<init>(). This error is reported at image build time because class net.sf.oval.expression.ExpressionLanguageRegistry is registered for linking at image build time by command line.
Error encountered while parsing net.sf.oval.expression.ExpressionLanguageRegistry.getExpressionLanguage(ExpressionLanguageRegistry.java:78) 
Parsing context:
   at net.sf.oval.AbstractCheck.isActive(AbstractCheck.java:151)
   at net.sf.oval.Validator.checkConstraint(Validator.java:763)
   at net.sf.oval.Validator._validateStaticInvariants(Validator.java:670)
   at net.sf.oval.Validator.validateInvariants(Validator.java:1382)
   at net.sf.oval.Validator.validate(Validator.java:1308)
   at gdv.xport.feld.Feld.validateInvariants(Feld.java:623)
   at gdv.xport.feld.Feld.validate(Feld.java:605)
   at gdv.xport.feld.AlphaNumFeld.validate(AlphaNumFeld.java:161)
   at gdv.xport.feld.Feld.validate(Feld.java:601)
   at gdv.xport.feld.Satznummer.validate(Satznummer.java:232)
   at gdv.xport.feld.Feld.isValid(Feld.java:583)
   at gdv.xport.feld.Feld.isInvalid(Feld.java:592)
   at gdv.xport.satz.Teildatensatz.getSatznummer(Teildatensatz.java:146)
   at gdv.xport.satz.Teildatensatz.toShortString(Teildatensatz.java:589)
   at gdv.xport.satz.Teildatensatz.findFeld(Teildatensatz.java:352)
   at gdv.xport.satz.Teildatensatz.getFeld(Teildatensatz.java:343)
   at gdv.xport.satz.Satz.findFeld(Satz.java:620)
   at gdv.xport.satz.Satz.getFeld(Satz.java:614)
   at gdv.xport.satz.Vorsatz.getErstellungsZeitraumBis(Vorsatz.java:229)
   at gdv.xport.satz.Vorsatz.setErstellungsZeitraumVon(Vorsatz.java:214)
   at gdv.xport.Datenpaket.setErstellungsDatumVon(Datenpaket.java:592)
   at gdv.xport.Datenpaket.<init>(Datenpaket.java:75)
   at gdv.xport.Datenpaket.<init>(Datenpaket.java:62)
   at Main.main(Main.java:5)
   at static root method.(Unknown Source)
...

not providing any indication about the reason the said method is unresolved (in this case the absence of org/mozilla/javascript/Scriptable from the classpath.

#6245 was meant to address this but it looks like there are cases that still escape.

The issue seems to be caused when Graal ignores NoClassDefFoundErrors in

if (e.getCause() instanceof LinkageError || e.getCause() instanceof IllegalAccessError) {
/*
* Ignore LinkageError if thrown from eager resolution attempt. This is usually
* followed by a call to ConstantPool.lookupType() which should return an
* UnresolvedJavaType which we know how to deal with.
*/

this results in the eager resolution failure to not get logged as the cause of the UnresolvedElement.

cc @cstancu

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions