Skip to content

Commit 9a79691

Browse files
Throw more specific exceptions from JNI
1 parent 91de04f commit 9a79691

File tree

5 files changed

+47
-3
lines changed

5 files changed

+47
-3
lines changed

android-database-sqlcipher/src/main/cpp/net_sqlcipher_CursorWindow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ namespace sqlcipher {
9898
{
9999
char buf[100];
100100
snprintf(buf, sizeof(buf), "get field slot from row %d col %d failed", row, column);
101-
jniThrowException(env, "java/lang/IllegalStateException", buf);
101+
jniThrowException(env, "net/sqlcipher/InvalidRowColumnException", buf);
102102
}
103103

104104
static void throwUnknowTypeException(JNIEnv * env, jint type)
105105
{
106106
char buf[80];
107107
snprintf(buf, sizeof(buf), "UNKNOWN type %d", type);
108-
jniThrowException(env, "java/lang/IllegalStateException", buf);
108+
jniThrowException(env, "net/sqlcipher/UnknownTypeException", buf);
109109
}
110110

111111
static jlong getLong_native(JNIEnv * env, jobject object, jint row, jint column)

android-database-sqlcipher/src/main/cpp/net_sqlcipher_database_SQLiteQuery.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ static jint native_fill_window(JNIEnv* env, jobject object, jobject javaWindow,
210210
field_slot_t * fieldDir = window->allocRow();
211211
if(!fieldDir) {
212212
LOG_WINDOW("Failed to allocate row in reset, bailing\n");
213-
return startPos + numRows + finish_program_and_get_row_count(statement) + 1;
213+
jniThrowException(env, "net/sqlcipher/RowAllocationException",
214+
"Failed to allocate row in reset within native_fill_window");
214215
} else {
215216
LOG_WINDOW("Allocated row in reset set\n");
216217
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package net.sqlcipher;
2+
3+
/**
4+
* An exception that indicates there was an error accessing a specific row/column.
5+
*/
6+
public class InvalidRowColumnException extends RuntimeException
7+
{
8+
public InvalidRowColumnException() {}
9+
10+
public InvalidRowColumnException(String error)
11+
{
12+
super(error);
13+
}
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package net.sqlcipher;
2+
3+
/**
4+
* An exception that indicates there was an error attempting to allocate a row
5+
* for the CursorWindow.
6+
*/
7+
public class RowAllocationException extends RuntimeException
8+
{
9+
public RowAllocationException() {}
10+
11+
public RowAllocationException(String error)
12+
{
13+
super(error);
14+
}
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package net.sqlcipher;
2+
3+
/**
4+
* An exception that indicates an unknown type was returned.
5+
*/
6+
public class UnknownTypeException extends RuntimeException
7+
{
8+
public UnknownTypeException() {}
9+
10+
public UnknownTypeException(String error)
11+
{
12+
super(error);
13+
}
14+
}

0 commit comments

Comments
 (0)