Skip to content

Possible occur NullpointerException on MyBatisCursorItemReader when close #237

Closed
@kazuki43zoo

Description

@kazuki43zoo

In the current implementation of MyBatisCursorItemReader, there is possible that NullpointerException occurs when implements application code as follow:

Application code:

try {
    reader.open(...);
    // ...
} finally {
    reader.close();
}

MyBatisCursorItemReader:

@Override
protected void doOpen() throws Exception {
  Map<String, Object> parameters = new HashMap<>();
  if (parameterValues != null) {
    parameters.putAll(parameterValues);
  }

  sqlSession = sqlSessionFactory.openSession(ExecutorType.SIMPLE);  
  cursor = sqlSession.selectCursor(queryId, parameters); // <- when occurs exception, a cursor is null
  cursorIterator = cursor.iterator();
}

@Override
protected void doClose() throws Exception {
  cursor.close(); // <- occurs NullpointerException
  sqlSession.close();
  cursorIterator = null;
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions