From 4a79dbe0102068bc7c0be0bb8b3db6a7d49511c0 Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Wed, 14 Jun 2017 10:07:30 +0700 Subject: [PATCH] StatementExtractor: better diagnostics if parent is unexpectedly null Review: IDEA-CR-21189 --- .../src/com/siyeh/ig/psiutils/StatementExtractor.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/StatementExtractor.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/StatementExtractor.java index c2e917d42179..82af144cd8b4 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/StatementExtractor.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/StatementExtractor.java @@ -73,7 +73,10 @@ public class StatementExtractor { } parent = ObjectUtils.tryCast(parentElement, PsiExpression.class); if (parent == null) { - throw new RuntimeExceptionWithAttachments("Expected to have expression parent", + String message = PsiTreeUtil.isAncestor(root, expression, false) ? + "Expected to have expression parent" : + "Supplied root is not the expression ancestor"; + throw new RuntimeExceptionWithAttachments(message, new Attachment("expression.txt", expression.getText()), new Attachment("root.txt", root.getText())); }