From 0385947ef36aff2a79e6f5c0a1afdcfdfc6b336e Mon Sep 17 00:00:00 2001 From: Darin Wright Date: Mon, 29 Oct 2007 13:56:28 +0000 Subject: Bug 207743 StringIndexOutOfBoundsException in ConsoleDocumentAdapter --- .../internal/console/ConsoleDocumentAdapter.java | 47 ++++++++++++---------- 1 file changed, 25 insertions(+), 22 deletions(-) (limited to 'org.eclipse.ui.console') diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleDocumentAdapter.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleDocumentAdapter.java index 456e834cc..c5b18e629 100644 --- a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleDocumentAdapter.java +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleDocumentAdapter.java @@ -320,34 +320,37 @@ public class ConsoleDocumentAdapter implements IDocumentAdapter, IDocumentListen // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4994840 // see bug 84641 int offset = string.length() - 1; - while (string.charAt(offset) == '\r') { + while (offset >= 0 && string.charAt(offset) == '\r') { offset--; count++; } - if (offset < (string.length() - 1)) { - string = string.substring(0, offset); - } - - int lastIndex = 0; - int index = 0; - - Matcher matcher = pattern.matcher(string); - - while (matcher.find()) { - index = matcher.start(); + // if offset == 0, the line was all '\r' and there is no string to search for matches (bug 207743) + if (offset > 0) { + if (offset < (string.length() - 1)) { + string = string.substring(0, offset); + } - if (index == 0) - count++; - else if (index!=string.length()) - count++; + int lastIndex = 0; + int index = 0; - if (consoleWidth > 0) { - int lineLen = index - lastIndex + 1; - if (index == 0) lineLen += lengths[regionCount-1]; - count += lineLen/consoleWidth; - } + Matcher matcher = pattern.matcher(string); - lastIndex = index; + while (matcher.find()) { + index = matcher.start(); + + if (index == 0) + count++; + else if (index!=string.length()) + count++; + + if (consoleWidth > 0) { + int lineLen = index - lastIndex + 1; + if (index == 0) lineLen += lengths[regionCount-1]; + count += lineLen/consoleWidth; + } + + lastIndex = index; + } } return count; } -- cgit v1.2.3