Home » Java » java – IllegalArgumentException: Invalid column null in Path of Security January of 2020-Exceptionshub

java – IllegalArgumentException: Invalid column null in Path of Security January of 2020-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I came across the following code used how my projection in query of SQLiteQueryBuilder.

String[] selectFields = new String[5];
selectFields[0] = "pmp_id";

In versions of path of security of Android until 01/01/2020 (dd/MM/yyyy) this code work correctly. In version of path of 01/01/2020 the app generate the error:

java.lang.IllegalArgumentException: Invalid column null
    at android.database.sqlite.SQLiteQueryBuilder.computeSingleProjectionOrThrow(SQLiteQueryBuilder.java:1142)
    at android.database.sqlite.SQLiteQueryBuilder.computeProjection(SQLiteQueryBuilder.java:1113)
    at android.database.sqlite.SQLiteQueryBuilder.buildQuery(SQLiteQueryBuilder.java:888)
    at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:561)
    at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:475)

I already fixed the error this way:

String[] selectFields = { "pmp_id" };

But i would like to understand why in old versions it works and in new ones it doesn’t?

How to&Answers:

new String[5] creates an array of five String references and you’re only assigning to the first slot. Remaining slots stay null.

Why this started crashing after a recent update seems to be explained in this commit that changes SQLiteQueryBuilder to be stricter with its inputs:

This change also offers setStrictColumns() to require that all
untrusted column names are valid, such as those in ContentValues.