use of java.lang.IllegalArgumentException in project j2objc by google.
the class RC2ParameterSpecTest method testRC2ParameterSpec2.
/**
* RC2ParameterSpec(int effectiveKeyBits, byte[] iv, int offset) method
* testing. Tests that IllegalArgumentException is thrown in the case of
* inappropriate constructor parameters and that input iv array is
* copied to protect against subsequent modification.
*/
public void testRC2ParameterSpec2() {
int effectiveKeyBits = 10;
byte[] iv = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
int offset = 2;
try {
new RC2ParameterSpec(effectiveKeyBits, null, offset);
fail("An IllegalArgumentException should be thrown " + "in the case of null iv.");
} catch (IllegalArgumentException e) {
}
try {
new RC2ParameterSpec(effectiveKeyBits, iv, 4);
fail("An IllegalArgumentException should be thrown " + "in the case of short iv.");
} catch (IllegalArgumentException e) {
}
RC2ParameterSpec ps = new RC2ParameterSpec(effectiveKeyBits, iv, offset);
iv[offset]++;
assertFalse("The change of iv specified in the constructor " + "should not cause the change of internal array.", iv[offset] == ps.getIV()[0]);
}
use of java.lang.IllegalArgumentException in project j2objc by google.
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.IllegalArgumentException in project android_packages_apps_Gallery2 by LineageOS.
the class Wallpaper method onResume.
@SuppressWarnings("fallthrough")
@Override
protected void onResume() {
super.onResume();
Intent intent = getIntent();
switch(mState) {
case STATE_INIT:
{
mPickedItem = intent.getData();
if (mPickedItem == null) {
Intent request = new Intent(Intent.ACTION_GET_CONTENT).setClass(this, DialogPicker.class).setType(IMAGE_TYPE);
startActivityForResult(request, STATE_PHOTO_PICKED);
return;
}
mState = STATE_PHOTO_PICKED;
// fall-through
}
case STATE_PHOTO_PICKED:
{
Intent cropAndSetWallpaperIntent;
boolean fromScreenColor = false;
// Do this for screencolor select and crop image to preview.
Bundle extras = intent.getExtras();
if (extras != null) {
fromScreenColor = extras.getBoolean(KEY_FROM_SCREENCOLOR, false);
}
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) && (!fromScreenColor)) {
WallpaperManager wpm = WallpaperManager.getInstance(getApplicationContext());
try {
cropAndSetWallpaperIntent = wpm.getCropAndSetWallpaperIntent(mPickedItem);
startActivity(cropAndSetWallpaperIntent);
finish();
return;
} catch (ActivityNotFoundException anfe) {
// ignored; fallthru to existing crop activity
} catch (IllegalArgumentException iae) {
// ignored; fallthru to existing crop activity
}
}
int width, height;
float spotlightX, spotlightY;
if (fromScreenColor) {
width = extras.getInt(KEY_ASPECT_X, 0);
height = extras.getInt(KEY_ASPECT_Y, 0);
spotlightX = extras.getFloat(KEY_SPOTLIGHT_X, 0);
spotlightY = extras.getFloat(KEY_SPOTLIGHT_Y, 0);
} else {
width = getWallpaperDesiredMinimumWidth();
height = getWallpaperDesiredMinimumHeight();
Point size = getDefaultDisplaySize(new Point());
spotlightX = (float) size.x / width;
spotlightY = (float) size.y / height;
}
// Don't set wallpaper from screencolor.
cropAndSetWallpaperIntent = new Intent(CropActivity.CROP_ACTION).setClass(this, CropActivity.class).setDataAndType(mPickedItem, IMAGE_TYPE).addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT).putExtra(CropExtras.KEY_OUTPUT_X, width).putExtra(CropExtras.KEY_OUTPUT_Y, height).putExtra(CropExtras.KEY_ASPECT_X, width).putExtra(CropExtras.KEY_ASPECT_Y, height).putExtra(CropExtras.KEY_SPOTLIGHT_X, spotlightX).putExtra(CropExtras.KEY_SPOTLIGHT_Y, spotlightY).putExtra(CropExtras.KEY_SCALE, true).putExtra(CropExtras.KEY_SCALE_UP_IF_NEEDED, true).putExtra(CropExtras.KEY_SET_AS_WALLPAPER, !fromScreenColor);
startActivity(cropAndSetWallpaperIntent);
finish();
}
}
}
use of java.lang.IllegalArgumentException in project clochure by videlalvaro.
the class LispReader method readUnicodeChar.
private static int readUnicodeChar(String token, int offset, int length, int base) {
if (token.length() != offset + length)
throw new IllegalArgumentException("Invalid unicode character: \\" + token);
int uc = 0;
for (int i = offset; i < offset + length; ++i) {
int d = Character.digit(token.charAt(i), base);
if (d == -1)
throw new IllegalArgumentException("Invalid digit: " + token.charAt(i));
uc = uc * base + d;
}
return (char) uc;
}
use of java.lang.IllegalArgumentException in project clochure by videlalvaro.
the class LispReader method readUnicodeChar.
private static int readUnicodeChar(PushbackReader r, int initch, int base, int length, boolean exact) {
int uc = Character.digit(initch, base);
if (uc == -1)
throw new IllegalArgumentException("Invalid digit: " + (char) initch);
int i = 1;
for (; i < length; ++i) {
int ch = read1(r);
if (ch == -1 || isWhitespace(ch) || isMacro(ch)) {
unread(r, ch);
break;
}
int d = Character.digit(ch, base);
if (d == -1)
throw new IllegalArgumentException("Invalid digit: " + (char) ch);
uc = uc * base + d;
}
if (i != length && exact)
throw new IllegalArgumentException("Invalid character length: " + i + ", should be: " + length);
return uc;
}
Aggregations