diff options
author | Paul Pazderski | 2020-01-03 11:48:16 +0000 |
---|---|---|
committer | Paul Pazderski | 2020-01-06 08:27:08 +0000 |
commit | 9fae9caf849cc3428e20a680145072eb0372c891 (patch) | |
tree | 3091ffa030b6dba90caef2a1359e2a273bdea55a | |
parent | 9053ccf04b5d2e8bee7ed04a49a1153d540e2237 (diff) | |
download | eclipse.platform.text-9fae9caf849cc3428e20a680145072eb0372c891.tar.gz eclipse.platform.text-9fae9caf849cc3428e20a680145072eb0372c891.tar.xz eclipse.platform.text-9fae9caf849cc3428e20a680145072eb0372c891.zip |
Bug 558781 - TextPresentation iterator catches wrong exception
Change-Id: Ie50c2216c58656079ad00fd8938d03818e5a385b
Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
-rw-r--r-- | org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextPresentationTest.java | 25 | ||||
-rw-r--r-- | org.eclipse.jface.text/src/org/eclipse/jface/text/TextPresentation.java | 25 |
2 files changed, 31 insertions, 19 deletions
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextPresentationTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextPresentationTest.java index 41289bb46f2..8e70ca0c028 100644 --- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextPresentationTest.java +++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextPresentationTest.java @@ -16,10 +16,12 @@ package org.eclipse.jface.text.tests; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; +import java.util.NoSuchElementException; import org.junit.After; import org.junit.Before; @@ -1250,6 +1252,29 @@ public class TextPresentationTest { shell.dispose(); } } + + @Test + public void testIterator() { + // Test read over iterator end + Iterator<StyleRange> e= fTextPresentation.getAllStyleRangeIterator(); + try { + for (int i= 0; i < 1000; i++) { + e.next(); + } + fail("Iterator has no end."); + } catch (NoSuchElementException ex) { + // expected + } + e= fTextPresentation.getNonDefaultStyleRangeIterator(); + try { + for (int i= 0; i < 1000; i++) { + e.next(); + } + fail("Iterator has no end."); + } catch (NoSuchElementException ex) { + // expected + } + } // helper method required as long as TextPresentation methods manipulate given arguments private static StyleRange[] deepClone(StyleRange[] original) { diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextPresentation.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextPresentation.java index ff79eff039e..42dab5fc166 100644 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextPresentation.java +++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextPresentation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -98,7 +98,7 @@ public class TextPresentation { try { StyleRange r= fRanges.get(fIndex++); return createWindowRelativeRange(fWindow, r); - } catch (ArrayIndexOutOfBoundsException x) { + } catch (IndexOutOfBoundsException x) { throw new NoSuchElementException(); } finally { if (fSkipDefaults) @@ -111,11 +111,6 @@ public class TextPresentation { return fIndex < fLength; } - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - /** * Returns whether the given object should be skipped. * @@ -132,7 +127,7 @@ public class TextPresentation { */ protected void computeIndex() { while (fIndex < fLength && skip(fRanges.get(fIndex))) - ++ fIndex; + ++fIndex; } } @@ -651,15 +646,11 @@ public class TextPresentation { */ public StyleRange getFirstStyleRange() { try { - StyleRange range= fRanges.get(getFirstIndexInWindow(fResultWindow)); return createWindowRelativeRange(fResultWindow, range); - - } catch (NoSuchElementException x) { - } catch (IndexOutOfBoundsException x) { + } catch (NoSuchElementException | IndexOutOfBoundsException x) { + return null; } - - return null; } /** @@ -669,13 +660,9 @@ public class TextPresentation { */ public StyleRange getLastStyleRange() { try { - StyleRange range= fRanges.get(getFirstIndexAfterWindow(fResultWindow) - 1); return createWindowRelativeRange(fResultWindow, range); - - } catch (NoSuchElementException x) { - return null; - } catch (IndexOutOfBoundsException x) { + } catch (NoSuchElementException | IndexOutOfBoundsException x) { return null; } } |