[java] Add more details to parse failures in signatures

This commit is contained in:
Clément Fournier 2024-11-21 14:55:51 +01:00
parent 28b4139cd4
commit 0d11f151bd
No known key found for this signature in database
GPG Key ID: 6F9389D8E390BD4C
2 changed files with 14 additions and 3 deletions

View File

@ -31,6 +31,7 @@ import net.sourceforge.pmd.lang.java.types.JTypeVar;
import net.sourceforge.pmd.lang.java.types.LexicalScope;
import net.sourceforge.pmd.lang.java.types.Substitution;
import net.sourceforge.pmd.lang.java.types.TypeOps;
import net.sourceforge.pmd.util.AssertionUtil;
import net.sourceforge.pmd.util.CollectionUtil;
abstract class GenericSigBase<T extends JTypeParameterOwnerSymbol & AsmStub> {
@ -51,8 +52,18 @@ abstract class GenericSigBase<T extends JTypeParameterOwnerSymbol & AsmStub> {
this.lock = new ParseLock(parseLockName) {
@Override
protected boolean doParse() {
try {
GenericSigBase.this.doParse();
return true;
} catch (RuntimeException e) {
throw AssertionUtil.contexted(e)
.addContextValue("signature", GenericSigBase.this)
// Here we don't use the toString of the ctx directly because
// it could be using the signature indirectly, which would fail
.addContextValue("owner class", ctx.getEnclosingClass())
.addContextValue("owner name", ctx.getSimpleName())
.addContextValue("owner package", ctx.getPackageName());
}
}
@Override

View File

@ -50,7 +50,7 @@ abstract class ParseLock {
finishParse(!success);
} catch (Throwable t) {
status = ParseStatus.FAILED;
LOG.error("Parsing failed in ParseLock#doParse()", t);
LOG.error("Parsing failed in ParseLock#doParse() of {}", name, t);
finishParse(true);
}