From 0d11f151bd6ec67e2bb28b9c155f3e046382c8e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Thu, 21 Nov 2024 14:55:51 +0100 Subject: [PATCH] [java] Add more details to parse failures in signatures --- .../java/symbols/internal/asm/GenericSigBase.java | 15 +++++++++++++-- .../lang/java/symbols/internal/asm/ParseLock.java | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/internal/asm/GenericSigBase.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/internal/asm/GenericSigBase.java index eabeb13c5a..07555bae9e 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/internal/asm/GenericSigBase.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/internal/asm/GenericSigBase.java @@ -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 { @@ -51,8 +52,18 @@ abstract class GenericSigBase { this.lock = new ParseLock(parseLockName) { @Override protected boolean doParse() { - GenericSigBase.this.doParse(); - return true; + 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 diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/internal/asm/ParseLock.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/internal/asm/ParseLock.java index a0150e00fe..d78f9e51cd 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/internal/asm/ParseLock.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/internal/asm/ParseLock.java @@ -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); }