@MJI
public char charAt__I__C (MJIEnv env, int objRef, int index){
char[] data = env.getStringChars(objRef);
- return data[index];
+ if (index >= 0 && index < data.length) {
+ return data[index];
+ }
+ env.throwException("java.lang.StringIndexOutOfBoundsException",
+ "String index out of range: " + index);
+ return '\0';
}
}
}
+ @Test
+ public void testCharAtOutOfBounds() {
+ if (verifyNoPropertyViolation()){
+ try {
+ "".charAt(0);
+ } catch (StringIndexOutOfBoundsException e) {
+ return;
+ }
+ assert false;
+ }
+ }
+
+ @Test
+ public void testCharAtOutOfBoundsNeg() {
+ boolean passed = false;
+ if (verifyNoPropertyViolation()){
+ try {
+ assert(" ".charAt(0) == ' ');
+ passed = true;
+ " ".charAt(-1);
+ } catch (StringIndexOutOfBoundsException e) {
+ assert(passed);
+ return;
+ }
+ assert false;
+ }
+ }
+
@Test
@SuppressWarnings("deprecation")
public void testConstructors(){