Intermittent Java - MySQL connection Exception | Play Java

孤街浪徒 提交于 2019-12-24 06:16:12

问题


I am using Play framework(JAVA) to connect to MYSQL. While interacting with the database, I am getting an intermittent(20% times) the error with exception:

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[NullPointerException: null]] at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:265) ~[play_2.10-2.4.2.jar:2.4.2] at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:191) ~[play_2.10-2.4.2.jar:2.4.2] at play.api.GlobalSettings$class.onError(GlobalSettings.scala:179) [play_2.10-2.4.2.jar:2.4.2] at play.api.DefaultGlobal$.onError(GlobalSettings.scala:212) [play_2.10-2.4.2.jar:2.4.2] at play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorHandler.scala:94) [play_2.10-2.4.2.jar:2.4.2] at play.filters.cors.AbstractCORSPolicy$$anonfun$1.applyOrElse(AbstractCORSPolicy.scala:151) [filters-helpers_2.10-2.4.2.jar:2.4.2] at play.filters.cors.AbstractCORSPolicy$$anonfun$1.applyOrElse(AbstractCORSPolicy.scala:150) [filters-helpers_2.10-2.4.2.jar:2.4.2] at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:344) [scala-library-2.10.5.jar:na] at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:343) [scala-library-2.10.5.jar:na] at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library-2.10.5.jar:na] at play.api.libs.iteratee.Execution$trampoline$.execute(Execution.scala:70) [play-iteratees_2.10-2.4.2.jar:2.4.2] at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40) [scala-library-2.10.5.jar:na] at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:248) [scala-library-2.10.5.jar:na] at scala.concurrent.Promise$class.tryFailure(Promise.scala:112) [scala-library-2.10.5.jar:na] at scala.concurrent.impl.Promise$DefaultPromise.tryFailure(Promise.scala:153) [scala-library-2.10.5.jar:na] at play.api.mvc.Filter$$anon$1$$anonfun$apply$4$$anonfun$apply$1.applyOrElse(Filters.scala:67) [play_2.10-2.4.2.jar:2.4.2] at play.api.mvc.Filter$$anon$1$$anonfun$apply$4$$anonfun$apply$1.applyOrElse(Filters.scala:61) [play_2.10-2.4.2.jar:2.4.2] at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:33) [scala-library-2.10.5.jar:na] at play.api.libs.iteratee.Iteratee$$anonfun$recoverM$1.applyOrElse(Iteratee.scala:629) [play-iteratees_2.10-2.4.2.jar:2.4.2] at play.api.libs.iteratee.Iteratee$$anonfun$recoverM$1.applyOrElse(Iteratee.scala:629) [play-iteratees_2.10-2.4.2.jar:2.4.2] at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:33) [scala-library-2.10.5.jar:na] at scala.util.Failure$$anonfun$recover$1.apply(Try.scala:185) [scala-library-2.10.5.jar:na] at scala.util.Try$.apply(Try.scala:161) [scala-library-2.10.5.jar:na] at scala.util.Failure.recover(Try.scala:185) [scala-library-2.10.5.jar:na] at scala.concurrent.Future$$anonfun$recover$1.apply(Future.scala:324) [scala-library-2.10.5.jar:na] at scala.concurrent.Future$$anonfun$recover$1.apply(Future.scala:324) [scala-library-2.10.5.jar:na] at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library-2.10.5.jar:na] at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55) [akka-actor_2.10-2.3.11.jar:na] at akka.dispatch.BatchingExecutor$BlockableBatch$$anonfun$run$1.apply$mcV$sp(BatchingExecutor.scala:91) [akka-actor_2.10-2.3.11.jar:na] at akka.dispatch.BatchingExecutor$BlockableBatch$$anonfun$run$1.apply(BatchingExecutor.scala:91) [akka-actor_2.10-2.3.11.jar:na] at akka.dispatch.BatchingExecutor$BlockableBatch$$anonfun$run$1.apply(BatchingExecutor.scala:91) [akka-actor_2.10-2.3.11.jar:na] at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:72) [scala-library-2.10.5.jar:na] at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:90) [akka-actor_2.10-2.3.11.jar:na] at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40) [akka-actor_2.10-2.3.11.jar:na] at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:397) [akka-actor_2.10-2.3.11.jar:na] at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library-2.10.5.jar:na] at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library-2.10.5.jar:na] at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library-2.10.5.jar:na] at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library-2.10.5.jar:na] Caused by: java.lang.NullPointerException: null at com.mysql.jdbc.ResultSetImpl.checkColumnBounds(ResultSetImpl.java:826) ~[mysql-connector-java-5.1.27.jar:na] at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2711) ~[mysql-connector-java-5.1.27.jar:na] at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2847) ~[mysql-connector-java-5.1.27.jar:na] at com.zaxxer.hikari.proxy.ResultSetJavassistProxy.getInt(ResultSetJavassistProxy.java) ~[HikariCP-2.3.7.jar:na] at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$2.doExtract(IntegerTypeDescriptor.java:61) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:254) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:250) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:230) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:331) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:668) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:606) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.loader.Loader.doQuery(Loader.java:829) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.loader.Loader.doList(Loader.java:2542) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.loader.Loader.list(Loader.java:2271) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:459) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:365) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:246) ~[hibernate-entitymanager-3.6.9.Final.jar:3.6.9.Final] at service.UserService.getSessionById(UserService.java:40) ~[classes/:na] at interceptors.SecuredAction.call(SecuredAction.java:26) ~[classes/:na]

The initial cause of this comes from Null pointer exception at

com.mysql.jdbc.ResultSetImpl.checkColumnBounds(ResultSetImpl.java:826)

The method in jar is as follows:

/**
  802        * Checks if columnIndex is within the number of columns in this result set.
  803        * 
  804        * @param columnIndex
  805        *            the index to check
  806        * 
  807        * @throws SQLException
  808        *             if the index is out of bounds
  809        */
  810       protected final void checkColumnBounds(int columnIndex) throws SQLException {
  811           if ((columnIndex < 1)) {
  812               throw SQLError.createSQLException(Messages.getString(
  813                       "ResultSet.Column_Index_out_of_range_low", new Object[] {
  814                               Constants.integerValueOf(columnIndex),
  815                               Constants.integerValueOf(this.fields.length) }),
  816                       SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor()); //$NON-NLS-1$
  817           } else if ((columnIndex > this.fields.length)) {
  818               throw SQLError.createSQLException(Messages.getString(
  819                       "ResultSet.Column_Index_out_of_range_high", new Object[] {
  820                               Constants.integerValueOf(columnIndex),
  821                               Constants.integerValueOf(this.fields.length) }),
  822                       SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor()); //$NON-NLS-1$
  823           }
  824   
  825           if (this.profileSql || this.useUsageAdvisor) {
  826               this.columnUsed[columnIndex - 1] = true;
  827           }
  828       }

I am not able to figure out what is the cause for the failure since the setup is working perfectly on 80% of the calls.

This error occurs after the

javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection

which I am trying to figure out separately and if they are related or not, but if the connection is not there and "this" is null, should the code not break much before line 826?

Can anyone please help with identifying the error? Thanks in advance.

来源:https://stackoverflow.com/questions/32834387/intermittent-java-mysql-connection-exception-play-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!