Refine ConstantFieldSubstitutionProcessor error handling

The upgrade to SLF4J 2 via gh-29152 has broken
ConstantFieldSubstitutionProcessor when the class processed
has both a static boolean field to make constant at build
time and a static logger.

This issue is about catching and logging those errors,
skipping the processing of such fields which will be
then evaluated at runtime.

Closes gh-29219
This commit is contained in:
Sébastien Deleuze 2022-09-29 12:42:51 +02:00
parent 9b577a8955
commit 3eaf326997
1 changed files with 13 additions and 5 deletions

View File

@ -66,14 +66,22 @@ class ConstantFieldSubstitutionProcessor extends SubstitutionProcessor {
String fieldIdentifier = declaringClass.toJavaName() + "#" + field.getName();
for (Pattern pattern : patterns) {
if (pattern.matcher(fieldIdentifier).matches()) {
JavaConstant constant = lookupConstant(declaringClass.toJavaName(), field.getName());
if (constant != null) {
// TODO Use proper logging only when --verbose is specified when https://github.com/oracle/graal/issues/4669 will be fixed
try {
JavaConstant constant = lookupConstant(declaringClass.toJavaName(), field.getName());
if (constant != null) {
// TODO Use proper logging only when --verbose is specified when https://github.com/oracle/graal/issues/4669 will be fixed
if (!this.seen.contains(fieldIdentifier)) {
this.seen.add(fieldIdentifier);
System.out.println("Field " + fieldIdentifier + " set to " + constant.toValueString() + " at build time");
}
return new ConstantReadableJavaField(field, constant);
}
}
catch (Throwable ex) {
if (!this.seen.contains(fieldIdentifier)) {
this.seen.add(fieldIdentifier);
System.out.println("Field " + fieldIdentifier + " set to " + constant.toValueString() + " at build time");
System.out.println("Processing of field " + fieldIdentifier + " skipped due the following error : " + ex.getMessage());
}
return new ConstantReadableJavaField(field, constant);
}
}
}