Java: capture top level wildcards to avoid missing unhandled exceptions in string templates

GitOrigin-RevId: 5642714ef490655d44331304e0a29b95b4de6c65
This commit is contained in:
Bas Leijdekkers
2023-08-31 15:17:20 +00:00
committed by intellij-monorepo-bot
parent 049e116d27
commit 193febffe6
2 changed files with 8 additions and 1 deletions
@@ -124,7 +124,7 @@ public final class PsiTemplateExpressionImpl extends ExpressionPsiElement implem
for (PsiClassType classType : PsiTypesUtil.getClassTypeComponents(type)) {
PsiType substituted = PsiUtil.substituteTypeParameter(classType, CommonClassNames.JAVA_LANG_STRING_TEMPLATE_PROCESSOR, 0, false);
if (substituted != null) {
return substituted;
return PsiUtil.captureToplevelWildcards(substituted, this);
}
}
return null;
@@ -104,6 +104,13 @@ class X {
public static void testCapturedWilcard(StringTemplate.Processor<?, ?> str) {
Object s = <error descr="Unhandled exception: java.lang.Throwable">str."";</error>
}
void testCapturedWildcard2() {
StringTemplate.Processor<StringTemplate.Processor<?, ? extends Exception>, RuntimeException> processor = null;
Object o = <error descr="Unhandled exception: java.lang.Exception">processor."""
"""."""
""";</error>
}
public static void noNewlineAfterTextBlockOpeningQuotes() {
System.out.println(STR.<error descr="Illegal text block start: missing new line after opening quotes">"""</error>\{}""");