diff --git a/platform/lang-impl/src/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java index 2d1759ac7340..b1653d81eb3c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java @@ -640,7 +640,9 @@ public class CommentByLineCommentHandler extends MultiCaretCodeInsightActionHand } } else { - if (block.addSpace && document.getCharsSequence().charAt(shiftedStartOffset) != '\n') { + if (block.addSpace && + shiftedStartOffset < document.getTextLength() && + document.getCharsSequence().charAt(shiftedStartOffset) != '\n') { prefix += ' '; } document.insertString(offset, prefix);