Convert asserts to exceptions where the conditions could be false in a correct, bug-free program -- makes sure caller errors are caught and reported meaningfully

git-svn-id: https://zxing.googlecode.com/svn/trunk@840 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2009-02-05 13:06:19 +00:00
parent 07db37e997
commit 1c539c66a4
3 changed files with 9 additions and 5 deletions

View file

@ -40,11 +40,12 @@ final class YUVMonochromeBitmapSource extends BaseMonochromeBitmapSource {
* @param crop The rectangle within the yuvData to expose to MonochromeBitmapSource users
*/
YUVMonochromeBitmapSource(byte[] yuvData, int dataWidth, int dataHeight, Rect crop) {
if (crop.width() > dataWidth || crop.height() > dataHeight) {
throw new IllegalArgumentException();
}
mYUVData = yuvData;
mDataWidth = dataWidth;
mCrop = crop;
assert (crop.width() <= dataWidth);
assert (crop.height() <= dataHeight);
}
@Override

View file

@ -27,8 +27,10 @@ public final class BenchmarkItem {
private BarcodeFormat mFormat;
public BenchmarkItem(String path, int runs) {
if (runs <= 0) {
throw new IllegalArgumentException();
}
mPath = path;
assert(runs > 0);
mTimes = new int[runs];
mPosition = 0;
mDecoded = false;

View file

@ -67,8 +67,9 @@ final class SaveThread extends Thread {
private void save(byte[] data, int width, int height) {
int framingWidth = mFramingRect.width();
int framingHeight = mFramingRect.height();
assert (framingWidth <= width);
assert (framingHeight <= height);
if (framingWidth > width || framingHeight > height) {
throw new IllegalArgumentException();
}
int leftOffset = mFramingRect.left;
int topOffset = mFramingRect.top;