commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Douglas Stevens (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DBUTILS-133) ON DUPLICATE KEY clause can cause NPE with QueryRunner.insert
Date Fri, 20 Jan 2017 16:05:27 GMT

    [ https://issues.apache.org/jira/browse/DBUTILS-133?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15832019#comment-15832019
] 

Douglas Stevens commented on DBUTILS-133:
-----------------------------------------

I think I may know what the issue is. I believe it is an auto-boxing NPE. That is, insert()
is returning a Long. In the case of a duplicate key update vs. a new row insert the Long value
returned is null. My code is assigning that to a long, the conversion is automatic and is
probably causing the NPE.

I'll adjust my code accordingly to see if the issue goes away. Will take a couple of weeks
to be sure but I am pretty confident that is the issue.

Thanks for asking for the stack trace... forced me to think a little more carefully about
my line of code.

> ON DUPLICATE KEY clause can cause NPE with QueryRunner.insert
> -------------------------------------------------------------
>
>                 Key: DBUTILS-133
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-133
>             Project: Commons DbUtils
>          Issue Type: Bug
>    Affects Versions: 1.6
>         Environment: Java 8, Mysql (mysql.mysql-connector-java.version = 5.1.40)
>            Reporter: Douglas Stevens
>
> Using QueryRunner.insert with an ON DUPLICATE KEY clause in the query may cause a NullPointerException,
presumably when there is no new row and therefore no new row id to return. Here is an example.
The NPE is reported on the line with 'id = query.insert('. Have seen other examples of the
same behavior.
> {code:java}
>         long id = 0;
>         try {
>             QueryRunner qry = new QueryRunner(myDataSource);
>             id = qry.insert(
>                     "INSERT INTO VinDecodeCache (License, State, Vin, Make, Model, Trim,
Engine, Year, "
>                             + "BaseId, MakeId, ModelId, TrimId, EngineId, CreateDate)
"
>                             + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE
KEY UPDATE "
>                             + "Vin = ?, Make = ?, Model = ?, Trim = ?, Engine = ?, Year
= ?, "
>                             + "BaseId = ?, MakeId = ?, ModelId = ?, TrimId = ?, EngineId
= ?, CreateDate = ?",
>                     new ScalarHandler<Long>(), license, state, vin, make, model,
trim, engine, year, baseId, makeId,
>                     modelId, trimId, engineId, now, vin, make, model, trim, engine, year,
baseId, makeId, modelId,
>                     trimId, engineId, new Date());
>         } catch (Exception e) {
>             LOG.error("Unexpected error caching vin decode data", e);
>             id = 0;
>         }
>         return id;
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message