Hi all

Since I haven't hear from you .. I dig more trying to find what wrong or what I did wrong and I just get more evidence that is a bug and it seems to be a major one? Since it`s the first time I use this version of ibatis and since it`s really basic I do think it`s because I'm missing something obvious but I have no idea. Please look at what I have found:

on the 1 call the following constructor is called: public SqlMapSessionImpl(ExtendedSqlMapClient client). This initialize the SessionScope object i.e: setting the sqlMapExecutor, etc.. When my code calls: sqlMap.setUserConnection(null); this method should reset the connection. But in fact the state of the SqlMapSessionImpl associated with the current thread is compromised because this setUserConnection has reseted the sessionScope object (See SqlMapExecutorDelegate.setUserProvidedTransaction()) associated with this SqlMapSessionImpl and put It back into the pool. BUT the sessionScope is still into the SqlMapSessionImpl (and the SqlMapSessionImpl is still Not closed).

When I another call the SqlMapSessionImpl will be reused with the sessionScope object that have been reseted: I can see the sqlMapExecutor set to null witch is not the case with the first call.

From there the bug will occurs only if the sqlMapExecutor is involved. In fact this is still unclear to me but I tried calling 2 times the same line of code that calls sqlMap.queryForObject(mapKey, param); But without error. Is the sqlMapExecutor is involved? Does another sqlMapExecutor is used? I have no Idea.

To reproduce the bug you must use the sqlMap.queryForPaginatedList method the second time. You will get the NullPointerException because theSessionScope.sqlMapExecutor is NULL.

In fact if you use the debugger an trace the SqlMapClientImpl object

private SqlMapSessionImpl getLocalSqlMapSession() {
SqlMapSessionImpl sqlMapSession = (SqlMapSessionImpl) localSqlMapSession.get();
   if (sqlMapSession == null || sqlMapSession.isClosed()) {
     sqlMapSession = new SqlMapSessionImpl(this);
     localSqlMapSession.set(sqlMapSession);
   }
   return sqlMapSession;
 }

between the 1 and second call you will that the SessionScope object is not consistent.

Hope that help. Like I said since I'm upgrading and don`t know well this version of ibatis I don`t really know what is the best approch to fix my problem. Any help is welcome.

Best Regards
/David

David Gagnon wrote:
Hi all,

I'm pretty sure this is a session problem. But there is an obscur point that look to me like a bug. It's surely not one though.

Trying to make the problem simple:

On the same http request (so same thread) the following function #1 is called followed by another. When the fynally is excuted from Function #1. The sessionScope get reseted and put back into the pool! But it's not removed from SqlMapSessionImpl!! When function #2 is called it grab the same SqlMapSessionImpl with the reseted SessionScope and that lead me to a NullPointerException.

I suppose my problem is simple to fix .. tanks for your help! That will bring me one step far in my upgrade process!
Best Regards


/David





Function #1
------------
public Object getObject(DbConnection dbCon, String mapKey, Object param, boolean mustFind) throws DatabaseException, SQLException {

       Object result = null;
       boolean handleTransactionLocally = false;
       try {
           if (dbCon == null) {
               handleTransactionLocally = true;
               dbCon = connectionFactory.getConnection();
               // TODO: check if that really usefull
               dbCon.setReadOnlyConnection(true);
           }

// MappedStatement statement = sqlMap.getMappedStatement(mapKey); // result = statement.executeQueryForObject(dbCon.getConnection(), param);

           sqlMap.setUserConnection(dbCon.getConnection());
           result = sqlMap.queryForObject(mapKey, param);

           if ((result == null) && (mustFind)) {
throw new DataNotFoundException("Object not found for param: (" + param.toString() + ")");
           }
       } catch (SQLException e) {
           if (handleTransactionLocally) {
ExceptionAdaptor.instance(exceptionAdaptorKey).getMappedException(e, "Unable to get: " + e.getMessage(), true, ExceptionAdaptor.ACTION_SEARCH, param);
           } else {
               throw e;
           }
       } finally {
           sqlMap.setUserConnection(null);
           if (dbCon != null)
           dbCon.closeAll(handleTransactionLocally);
       }
       return result;

   }
#Function 2
-------
public final SearchResult getListDynamicWithRowCount(String mapKey, String rowCountMapKey, Map param) throws DatabaseException {
       PaginatedList paginatedList = null;
       Integer nbRows = new Integer(-1);
       Integer pageSize = null;
       try {
paginatedList = sqlMap.queryForPaginatedList(mapKey, param, pageSize.intValue());


       } catch (SQLException e) {
//            log.error("Error during sql: " + e.getMessage(), e);
ExceptionAdaptor.instance(exceptionAdaptorKey).getMappedException(e, "getList: " + e.getMessage(), true, ExceptionAdaptor.ACTION_SEARCH, param);
       }

       return new SearchResult(paginatedList, nbRows.intValue());
   }


Exception:
java.lang.NullPointerException
at com.ibatis.sqlmap.engine.mapping.statement.PaginatedDataList.getList(PaginatedDataList.java:138) at com.ibatis.sqlmap.engine.mapping.statement.PaginatedDataList.pageTo(PaginatedDataList.java:98) at com.ibatis.sqlmap.engine.mapping.statement.PaginatedDataList.<init>(PaginatedDataList.java:46) at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForPaginatedList(SqlMapExecutorDelegate.java:667) at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForPaginatedList(SqlMapSessionImpl.java:109) at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForPaginatedList(SqlMapClientImpl.java:86) at com.davecorp.webos.dao.DaoSupport.getListDynamicWithRowCount(DaoSupport.java:205) at com.davecorp.webos.dao.DaoSupport.getListDynamicWithRowCount(DaoSupport.java:189) at com.unik.unikommerce.dao.resource.UkResourceDaoImpl.getResourceListDynamic(UkResourceDaoImpl.java:585) at com.unik.unikommerce.dao.resource.UkResourceDaoCachedImpl.getResourceListDynamic(UkResourceDaoCachedImpl.java:315) at com.unik.unikommerce.managers.InitUnikommerceApplicationManagerImpl.configureUserSession(InitUnikommerceApplicationManagerImpl.java:50) at com.davecorp.webos.struts.WindowEnabledRequestProcessor.processRequestSetup(WindowEnabledRequestProcessor.java:265) at com.davecorp.webos.struts.WindowEnabledRequestProcessor.process(WindowEnabledRequestProcessor.java:113) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at com.davecorp.webos.servlet.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:141) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
   at java.lang.Thread.run(Unknown Source)



#Function from SqlMapSessionImpl

private SqlMapSessionImpl getLocalSqlMapSession() {
SqlMapSessionImpl sqlMapSession = (SqlMapSessionImpl) localSqlMapSession.get();
   if (sqlMapSession == null || sqlMapSession.isClosed()) {
     sqlMapSession = new SqlMapSessionImpl(this);
     localSqlMapSession.set(sqlMapSession);
   }
   return sqlMapSession;
 }










Reply via email to