From 746cb5401f4d17d1af314d7d9cf9d7be7077ef7a Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Thu, 14 Mar 2024 13:03:00 +0100 Subject: [PATCH] [java-dfa] Report DFA exception if `myFlow.toString()` fails GitOrigin-RevId: 59409b57cb752d53d48122510925cf59be4b2ea3 --- .../StandardDataFlowInterpreter.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/dataFlow/interpreter/StandardDataFlowInterpreter.java b/platform/analysis-impl/src/com/intellij/codeInspection/dataFlow/interpreter/StandardDataFlowInterpreter.java index 4fccdcdfec8e..624796c4b349 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/dataFlow/interpreter/StandardDataFlowInterpreter.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/dataFlow/interpreter/StandardDataFlowInterpreter.java @@ -22,7 +22,10 @@ import one.util.streamex.StreamEx; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; /** * Standard interpreter implementation @@ -362,13 +365,22 @@ public class StandardDataFlowInterpreter implements DataFlowInterpreter { private void reportDfaProblem(@Nullable DfaInstructionState lastInstructionState, @NotNull Throwable e) { Attachment[] attachments = {new Attachment("method_body.txt", myPsiAnchor.getText())}; - String flowText = myFlow.toString(); - if (lastInstructionState != null) { - int index = lastInstructionState.getInstruction().getIndex(); - flowText = flowText.replaceAll("(?m)^", " "); - flowText = flowText.replaceFirst("(?m)^ {2}" + index + ": ", "* " + index + ": "); + try { + String flowText = myFlow.toString(); + if (lastInstructionState != null) { + int index = lastInstructionState.getInstruction().getIndex(); + flowText = flowText.replaceAll("(?m)^", " "); + flowText = flowText.replaceFirst("(?m)^ {2}" + index + ": ", "* " + index + ": "); + } + attachments = ArrayUtil.append(attachments, new Attachment("flow.txt", flowText)); + } + catch (ProcessCanceledException pce) { + throw pce; + } + catch (Exception ex) { + ex.addSuppressed(e); + LOG.error("While gathering flow text", ex); } - attachments = ArrayUtil.append(attachments, new Attachment("flow.txt", flowText)); if (lastInstructionState != null) { DfaMemoryState memoryState = lastInstructionState.getMemoryState(); String memStateText = null;