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

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

Unfortunately the stack trace ends at my line of code. I've verified that the 
data source is valid and that none of the input parameters in this case are 
null (not that that should matter). I can probably dig up another example if 
you want (different code, different query). In that case I didn't require the 
returned id so I've changed the code to use update() instead of insert() and 
haven't seen further errors, but the error rate is low enough that I can't be 
sure that is a fix. However, if it is related to a missing return id in the 
case of update vs. insert as I suspect then I think the switch to using 
update() vs. insert() would cause the issue to go away in that case. 

Here is the full slf4j logger (logback) output with the stack trace:

2017-01-17 19:23:37.417 ERROR [http-nio-8080-exec-4] [104.235.172.141] [] [996] 
[vpq5e86nlvnl] c.w.service.common.types.VinDecode - Unexpected error caching 
vin decode datajava.lang.NullPointerException: null        at 
com.wrench.service.common.types.VinDecode.create(VinDecode.java:175) at 
com.wrench.service.common.util.VehicleUtils.lookupVehicle(VehicleUtils.java:147)
     at 
com.wrench.service.user.impl.LookupVehicleImpl.lookupVehicle(LookupVehicleImpl.java:58)
      at 
com.wrench.service.user.UserManagementImpl.lookupVehicle(UserManagementImpl.java:139)
        at 
com.wrench.service.user.UserManagementClient.lookupVehicle(UserManagementClient.java:240)
    at 
com.wrench.service.user.UserManagement.lookupVehicle(UserManagement.java:884)   
     at sun.reflect.GeneratedMethodAccessor2516.invoke(Unknown Source)       at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)     at 
com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
     at 
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
        at 
com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
 at 
com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
  at 
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at 
com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    at 
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at 
com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
 at 
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
       at 
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
       at 
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
        at 
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
        at 
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
     at 
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
     at 
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)   
    at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at 
com.wrench.service.common.filter.LoggingContextFilter.doFilter(LoggingContextFilter.java:86)
 at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at 
com.wrench.service.common.filter.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:66)
       at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
  at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
  at 
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
       at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)   
     at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at 
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
     at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:509)  at 
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1104)
  at 
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
      at 
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
  at 
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
    at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
     at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
     at 
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
   at java.lang.Thread.run(Thread.java:745)

> 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)

Reply via email to