Details
-
Improvement
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
TBD
-
None
-
None
Description
There is a patch for making XmlCursor and AutoCloseable to land on trunk later, but even without that patch, the XmlCursor.XmlBookmark method:
XmlCursor toBookmark(XmlCursor c)
is not friendly for knowing when the cursor should be closed. The implementation returns the same cursor used as an argument or a new one if the cursor didn't move, so the only way to be sure if the cursor is new and needs to be closed independently of the argument cursor is to do something like:
XmlCursor cursor2 = bookmark.toBookmark(cursor1);
... // use cursor 2
if (cursor2 != cursor1) {
cursor2.close();
}
In a try-with-resources situation:
try (XmlCursor cursor2 = bookmark.toBookmark(cursor1)) {
... // use cursor 2
}
cursor2 could be the same cursor1 and cursor1 could be prematurely closed