@Override public E next() { try { return arr[index++]; } catch (IndexOutOfBoundsException e) { throw new NoSuchElementException(e.getMessage()); } } };
@Override public void tracedRun(Throwable tracedThrowable) { final SectionTree tree = SectionTree.this; try { tree.applyChangeSetsToTargetUIThreadOnly(); } catch (IndexOutOfBoundsException e) { throw new RuntimeException(getDebugInfo(tree) + e.getMessage(), e); } } })
@Override public byte byteAt(int index) { try { return buffer.get(index); } catch (ArrayIndexOutOfBoundsException e) { throw e; } catch (IndexOutOfBoundsException e) { throw new ArrayIndexOutOfBoundsException(e.getMessage()); } }
@Override public byte nextByte() { try { return byteAt(position++); } catch (IndexOutOfBoundsException e) { throw new NoSuchElementException(e.getMessage()); } }
@Override public E next() { next = true; switch (size) { case 0: throw new NoSuchElementException(); case 1: switch (i) { case 0: ++i; return single; default: throw new NoSuchElementException(); } default: try { E e = list.get(i); ++i; return e; } catch (IndexOutOfBoundsException e) { throw new NoSuchElementException(e.getMessage()); } } }
public boolean isLive() { if (simpleExoPlayer == null) return false; try { return simpleExoPlayer.isCurrentWindowDynamic(); } catch (@NonNull IndexOutOfBoundsException ignored) { // Why would this even happen =( // But lets log it anyway. Save is save if (DEBUG) Log.d(TAG, "Could not update metadata: " + ignored.getMessage()); if (DEBUG) ignored.printStackTrace(); return false; } }
@Override public void tracedRun(Throwable tracedThrowable) { @ApplyNewChangeSet int source; final String attribution; synchronized (this) { if (!mIsPosted) { return; } source = mSource; attribution = mAttribution; mSource = ApplyNewChangeSet.NONE; mAttribution = null; mIsPosted = false; } try { applyNewChangeSet(source, attribution, tracedThrowable); } catch (IndexOutOfBoundsException e) { throw new RuntimeException(getDebugInfo(SectionTree.this) + e.getMessage(), e); } } }
@Override public ByteString substring(int beginIndex, int endIndex) { try { ByteBuffer slice = slice(beginIndex, endIndex); return new NioByteString(slice); } catch (ArrayIndexOutOfBoundsException e) { throw e; } catch (IndexOutOfBoundsException e) { throw new ArrayIndexOutOfBoundsException(e.getMessage()); } }
/** * Retrieves the i-th element of the node list. */ public TemplateModel get(int i) throws TemplateModelException { try { return new NodeListModel(nodes.get(i), namespaces); } catch (IndexOutOfBoundsException e) { throw new TemplateModelException("Index out of bounds: " + e.getMessage()); } }
private static void assertInvalidGetPositions(Block block, int[] positions, int offset, int length) { try { block.getPositions(positions, offset, length).getLong(0, 0); fail("Expected to fail"); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().startsWith("position is not valid")); } catch (IndexOutOfBoundsException e) { assertTrue(e.getMessage().startsWith("Invalid offset")); } } }
private void postNewChangeSets(Throwable tracedThrowable) { if (mUseBackgroundChangeSets) { applyChangeSetsToTargetBackgroundAllowed(); return; } if (isMainThread()) { try { applyChangeSetsToTargetUIThreadOnly(); } catch (IndexOutOfBoundsException e) { throw new RuntimeException(getDebugInfo(this) + e.getMessage(), e); } } else { sMainThreadHandler .obtainMessage( MESSAGE_WHAT_BACKGROUND_CHANGESET_STATE_UPDATED, new ThreadTracingRunnable(tracedThrowable) { @Override public void tracedRun(Throwable tracedThrowable) { final SectionTree tree = SectionTree.this; try { tree.applyChangeSetsToTargetUIThreadOnly(); } catch (IndexOutOfBoundsException e) { throw new RuntimeException(getDebugInfo(tree) + e.getMessage(), e); } } }) .sendToTarget(); } }
private void except() { java.util.ArrayList<Integer> arrlist = new java.util.ArrayList<Integer>( 5 ); arrlist.add( 20); arrlist.add(15 ); arrlist.add( 30 ); arrlist.add(45); try { ( arrlist ).remove( 2); } catch ( IndexOutOfBoundsException x ) { x.getMessage(); } org.junit.Assert.assertThat( "123", org.hamcrest.CoreMatchers.is( "123" ) ); org.junit.Assert.assertThat( "Help! Integers don't work", 0, org.hamcrest.CoreMatchers.is( 1 ) ); } }
@Test public void testValidIndex_withMessage_collection() { final Collection<String> coll = new ArrayList<>(); coll.add(null); coll.add(null); Validate.validIndex(coll, 0, "Broken: "); Validate.validIndex(coll, 1, "Broken: "); try { Validate.validIndex(coll, -1, "Broken: "); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { assertEquals("Broken: ", ex.getMessage()); } try { Validate.validIndex(coll, 2, "Broken: "); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { assertEquals("Broken: ", ex.getMessage()); } final List<String> strColl = Arrays.asList("Hi"); final List<String> test = Validate.validIndex(strColl, 0, "Message"); assertSame(strColl, test); }
@Test public void testValidIndex_collection() { final Collection<String> coll = new ArrayList<>(); coll.add(null); coll.add(null); Validate.validIndex(coll, 0); Validate.validIndex(coll, 1); try { Validate.validIndex(coll, -1); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { assertEquals("The validated collection index is invalid: -1", ex.getMessage()); } try { Validate.validIndex(coll, 2); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { assertEquals("The validated collection index is invalid: 2", ex.getMessage()); } final List<String> strColl = Arrays.asList("Hi"); final List<String> test = Validate.validIndex(strColl, 0); assertSame(strColl, test); }
assertTrue(e.getMessage().startsWith("Invalid offset")); assertTrue(e.getMessage().startsWith("Invalid offset"));
@Test public void testValidIndex_withMessage_array() { final Object[] array = new Object[2]; Validate.validIndex(array, 0, "Broken: "); Validate.validIndex(array, 1, "Broken: "); try { Validate.validIndex(array, -1, "Broken: "); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { assertEquals("Broken: ", ex.getMessage()); } try { Validate.validIndex(array, 2, "Broken: "); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { assertEquals("Broken: ", ex.getMessage()); } final String[] strArray = new String[]{"Hi"}; final String[] test = Validate.noNullElements(strArray, "Message"); assertSame(strArray, test); }
@Test public void testValidIndex_withMessage_charSequence() { final CharSequence str = "Hi"; Validate.validIndex(str, 0, "Broken: "); Validate.validIndex(str, 1, "Broken: "); try { Validate.validIndex(str, -1, "Broken: "); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { assertEquals("Broken: ", ex.getMessage()); } try { Validate.validIndex(str, 2, "Broken: "); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { assertEquals("Broken: ", ex.getMessage()); } final String input = "Hi"; final String test = Validate.validIndex(input, 0, "Message"); assertSame(input, test); }
@Test public void testValidIndex_charSequence() { final CharSequence str = "Hi"; Validate.validIndex(str, 0); Validate.validIndex(str, 1); try { Validate.validIndex(str, -1); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { assertEquals("The validated character sequence index is invalid: -1", ex.getMessage()); } try { Validate.validIndex(str, 2); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { assertEquals("The validated character sequence index is invalid: 2", ex.getMessage()); } final String input = "Hi"; final String test = Validate.validIndex(input, 0); assertSame(input, test); }
@Test public void testValidIndex_array() { final Object[] array = new Object[2]; Validate.validIndex(array, 0); Validate.validIndex(array, 1); try { Validate.validIndex(array, -1); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { assertEquals("The validated array index is invalid: -1", ex.getMessage()); } try { Validate.validIndex(array, 2); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { assertEquals("The validated array index is invalid: 2", ex.getMessage()); } final String[] strArray = new String[]{"Hi"}; final String[] test = Validate.noNullElements(strArray); assertSame(strArray, test); }
IndexOutOfBoundsException newIOOB = new IndexOutOfBoundsException(ioob.getMessage() + "@" + jmsMsg.getCoreMessage()); newIOOB.initCause(ioob); ActiveMQClientLogger.LOGGER.unableToGetMessage(newIOOB);