Do not swallow exception throwing IOOBE

#KTIJ-22746
This commit is contained in:
Vladimir Dolzhenko
2022-09-15 14:17:45 +02:00
committed by Space
parent 0814c0da57
commit da86e536ad
2 changed files with 11 additions and 4 deletions
@@ -242,9 +242,16 @@ public abstract class ExpressionTypingVisitorDispatcher extends KtVisitor<Kotlin
private static void logOrThrowException(@NotNull KtExpression expression, Throwable e) {
try {
String location;
try {
location = " in " + PsiDiagnosticUtils.atLocation(expression);
}
catch (Exception ex) {
location = "";
}
// This trows AssertionError in CLI and reports the error in the IDE
LOG.error(
new KotlinExceptionWithAttachments("Exception while analyzing expression at " + PsiDiagnosticUtils.atLocation(expression), e)
new KotlinExceptionWithAttachments("Exception while analyzing expression" + location, e)
.withAttachment("expression.kt", expression.getText())
);
}
@@ -62,12 +62,12 @@ public class PsiDiagnosticUtils {
int offset = textRange.getStartOffset();
VirtualFile virtualFile = file.getVirtualFile();
String pathSuffix = " in " + (virtualFile == null ? file.getName() : virtualFile.getPath());
return offsetToLineAndColumn(document, offset).toString() + pathSuffix;
return offsetToLineAndColumn(document, offset) + pathSuffix;
}
@NotNull
public static LineAndColumn offsetToLineAndColumn(@Nullable Document document, int offset) {
if (document == null) {
if (document == null || document.getTextLength() == 0) {
return new LineAndColumn(-1, offset, null);
}
@@ -145,7 +145,7 @@ public class PsiDiagnosticUtils {
return "(" + start.line + "," + start.column + "-" + end.column + ")";
}
return start.toString() + " - " + end.toString();
return start + " - " + end;
}
}
}