use of java.lang.ArrayIndexOutOfBoundsException in project robovm by robovm.
the class IvParameterSpecTest method testIvParameterSpec2.
/**
* IvParameterSpec(byte[] iv) constructor testing. Checks that
* NullPointerException is thrown in the case of null input
* array and that input array is copied during initialization.
*/
public void testIvParameterSpec2() {
try {
new IvParameterSpec(null, 1, 1);
fail("Should raise an IllegalArgumentException " + "in the case of null byte array.");
} catch (ArrayIndexOutOfBoundsException e) {
fail("Unexpected ArrayIndexOutOfBoundsException was thrown");
} catch (IllegalArgumentException e) {
} catch (NullPointerException e) {
fail("Unexpected NullPointerException was thrown");
}
try {
new IvParameterSpec(new byte[] { 1, 2, 3 }, 2, 2);
fail("Should raise an IllegalArgumentException " + "if (iv.length - offset < len).");
} catch (ArrayIndexOutOfBoundsException e) {
fail("Unexpected ArrayIndexOutOfBoundsException was thrown");
} catch (IllegalArgumentException e) {
} catch (NullPointerException e) {
fail("Unexpected NullPointerException was thrown");
}
try {
new IvParameterSpec(new byte[] { 1, 2, 3 }, -1, 1);
fail("Should raise an ArrayIndexOutOfBoundsException " + "if offset index bytes outside the iv.");
} catch (ArrayIndexOutOfBoundsException e) {
} catch (IllegalArgumentException e) {
fail("Unexpected IllegalArgumentException was thrown");
} catch (NullPointerException e) {
fail("Unexpected NullPointerException was thrown");
}
/* TODO: DRL fail with java.lang.NegativeArraySizeException
try {
new IvParameterSpec(new byte[] {1, 2, 3}, 1, -2);
fail("Should raise an ArrayIndexOutOfBoundsException "
+ "if len index bytes outside the iv.");
} catch(ArrayIndexOutOfBoundsException e) {
} catch(IllegalArgumentException e) {
fail("Unexpected IllegalArgumentException was thrown");
} catch(NullPointerException e) {
fail("Unexpected NullPointerException was thrown");
}
*/
byte[] iv = new byte[] { 1, 2, 3, 4, 5 };
IvParameterSpec ivps = new IvParameterSpec(iv, 0, iv.length);
iv[0]++;
assertFalse("The change of input array's content should not cause " + "the change of internal array", iv[0] == ivps.getIV()[0]);
//Regression for HARMONY-1089
try {
new IvParameterSpec(new byte[2], 2, -1);
fail("ArrayIndexOutOfBoundsException expected");
} catch (ArrayIndexOutOfBoundsException e) {
//expected
}
}
use of java.lang.ArrayIndexOutOfBoundsException in project quorrabot by GloriousEggroll.
the class Logger method run.
@Override
@SuppressWarnings("SleepWhileInLoop")
public void run() {
this.isRunning = true;
if (!new File("./logs/").exists()) {
new File("./logs/").mkdirs();
}
if (!new File("./logs/core").exists()) {
new File("./logs/core/").mkdirs();
}
if (!new File("./logs/core-error").exists()) {
new File("./logs/core-error/").mkdirs();
}
if (!new File("./logs/core-debug").exists()) {
new File("./logs/core-debug/").mkdirs();
}
while (!disposed) {
if (!queue.isEmpty()) {
SimpleDateFormat datefmt = new SimpleDateFormat("dd-MM-yyyy");
datefmt.setTimeZone(TimeZone.getTimeZone("EDT"));
String timestamp = datefmt.format(new Date());
// underlying streams automatically (FileOutputStream).
if (!timestamp.equals(this.curLogTimestamp)) {
if (this.psCore != null) {
this.psCore.close();
this.psCore = null;
}
if (psError != null) {
this.psError.close();
this.psError = null;
}
if (this.psDebug != null) {
this.psDebug.close();
this.psDebug = null;
}
this.curLogTimestamp = timestamp;
}
try {
if (queue.size() > 0) {
LogItem i = queue.remove(0);
switch(i.t) {
case Output:
if (this.psCore == null) {
this.fosCore = new FileOutputStream("./logs/core/" + timestamp + ".txt", true);
this.psCore = new PrintStream(this.fosCore);
}
this.psCore.println(i.s);
this.psCore.flush();
break;
case Input:
if (this.psCore == null) {
this.fosCore = new FileOutputStream("./logs/core/" + timestamp + ".txt", true);
this.psCore = new PrintStream(this.fosCore);
}
this.psCore.println(i.s);
this.psCore.flush();
break;
case Error:
if (this.psError == null) {
this.fosError = new FileOutputStream("./logs/core-error/" + timestamp + ".txt", true);
this.psError = new PrintStream(this.fosError);
}
this.psError.println(i.s);
this.psError.flush();
break;
case Debug:
if (this.psDebug == null) {
this.fosDebug = new FileOutputStream("./logs/core-debug/" + timestamp + ".txt", true);
this.psDebug = new PrintStream(this.fosDebug);
}
this.psDebug.println(i.s);
this.psDebug.flush();
break;
default:
if (this.psCore == null) {
this.fosCore = new FileOutputStream("./logs/core/" + timestamp + ".txt", true);
this.psCore = new PrintStream(this.fosCore);
}
this.psCore.println(i.s);
this.psCore.flush();
break;
}
}
} catch (FileNotFoundException ex) {
ex.printStackTrace(System.err);
} catch (SecurityException ex) {
ex.printStackTrace(System.err);
} catch (ArrayIndexOutOfBoundsException ex) {
/* At shutdown queue.remove(0) throws an exception sometimes, it is expected, do not clutter the console/error logs. */
}
} else {
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
ex.printStackTrace(System.err);
}
}
}
}
Aggregations