Robert Marcano created XMLBEANS-589:
---------------------------------------

             Summary: No try-with-resources friendly API at XmlCursor
                 Key: XMLBEANS-589
                 URL: https://issues.apache.org/jira/browse/XMLBEANS-589
             Project: XMLBeans
          Issue Type: Improvement
          Components: Cursor
    Affects Versions: TBD
            Reporter: Robert Marcano


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

 



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to