java.lang.IndexOutOfBoundsException.getMessage()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(131)

本文整理了Java中java.lang.IndexOutOfBoundsException.getMessage()方法的一些代码示例,展示了IndexOutOfBoundsException.getMessage()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IndexOutOfBoundsException.getMessage()方法的具体详情如下:
包路径:java.lang.IndexOutOfBoundsException
类名称:IndexOutOfBoundsException
方法名:getMessage

IndexOutOfBoundsException.getMessage介绍

暂无

代码示例

代码示例来源:origin: skylot/jadx

@Override
  public E next() {
    try {
      return arr[index++];
    } catch (IndexOutOfBoundsException e) {
      throw new NoSuchElementException(e.getMessage());
    }
  }
};

代码示例来源:origin: facebook/litho

@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);
  }
 }
})

代码示例来源:origin: com.google.protobuf/protobuf-java

@Override
public byte byteAt(int index) {
 try {
  return buffer.get(index);
 } catch (ArrayIndexOutOfBoundsException e) {
  throw e;
 } catch (IndexOutOfBoundsException e) {
  throw new ArrayIndexOutOfBoundsException(e.getMessage());
 }
}

代码示例来源:origin: com.google.protobuf/protobuf-java

@Override
public byte nextByte() {
 try {
  return byteAt(position++);
 } catch (IndexOutOfBoundsException e) {
  throw new NoSuchElementException(e.getMessage());
 }
}

代码示例来源:origin: alibaba/cobar

@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());
    }
  }
}

代码示例来源:origin: TeamNewPipe/NewPipe

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;
  }
}

代码示例来源:origin: facebook/litho

@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);
  }
 }
}

代码示例来源:origin: com.google.protobuf/protobuf-java

@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());
 }
}

代码示例来源:origin: org.freemarker/freemarker

/**
 * 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());
  }
}

代码示例来源:origin: prestodb/presto

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"));
    }
  }
}

代码示例来源:origin: facebook/litho

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();
 }
}

代码示例来源:origin: checkstyle/checkstyle

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 ) );
  }
}

代码示例来源:origin: org.apache.commons/commons-lang3

@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);
}

代码示例来源:origin: org.apache.commons/commons-lang3

@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);
}

代码示例来源:origin: prestodb/presto

assertTrue(e.getMessage().startsWith("Invalid offset"));
assertTrue(e.getMessage().startsWith("Invalid offset"));

代码示例来源:origin: org.apache.commons/commons-lang3

@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);
}

代码示例来源:origin: org.apache.commons/commons-lang3

@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);
}

代码示例来源:origin: org.apache.commons/commons-lang3

@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);
}

代码示例来源:origin: org.apache.commons/commons-lang3

@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);
}

代码示例来源:origin: wildfly/wildfly

IndexOutOfBoundsException newIOOB = new IndexOutOfBoundsException(ioob.getMessage() + "@" + jmsMsg.getCoreMessage());
newIOOB.initCause(ioob);
ActiveMQClientLogger.LOGGER.unableToGetMessage(newIOOB);

相关文章