File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
main/java/org/apache/ibatis/cursor/defaults
test/java/org/apache/ibatis/submitted/cursor_simple Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -94,6 +94,9 @@ public int getCurrentIndex() {
94
94
95
95
@ Override
96
96
public Iterator <T > iterator () {
97
+ if (isClosed ()) {
98
+ throw new IllegalStateException ("A Cursor is already closed." );
99
+ }
97
100
if (iteratorRetrieved ) {
98
101
throw new IllegalStateException ("Cannot open more than one iterator on a Cursor" );
99
102
}
Original file line number Diff line number Diff line change @@ -361,4 +361,18 @@ public void shouldGetAllUserUsingAnnotationBasedMapper() {
361
361
}
362
362
}
363
363
364
+ @ Test
365
+ public void shouldThrowIllegalStateExceptionUsingIteratorOnSessionClosed () {
366
+ Cursor <User > usersCursor ;
367
+ try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
368
+ usersCursor = sqlSession .getMapper (Mapper .class ).getAllUsers ();
369
+ }
370
+ try {
371
+ usersCursor .iterator ();
372
+ Assert .fail ("Should throws the IllegalStateException when call the iterator method after session is closed." );
373
+ } catch (IllegalStateException e ) {
374
+ Assert .assertEquals ("A Cursor is already closed." , e .getMessage ());
375
+ }
376
+ }
377
+
364
378
}
You can’t perform that action at this time.
0 commit comments