Uploaded image for project: 'XMLBeans'
  1. XMLBeans
  2. XMLBEANS-589

No try-with-resources friendly API at XmlCursor

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • TBD
    • None
    • Cursor
    • 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

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            robmv Robert Marcano
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: