Derby
  1. Derby
  2. DERBY-5960

VirtualRandomAccessFile.close() is not idempotent

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 10.10.1.1
    • Fix Version/s: 10.8.3.3, 10.9.2.2, 10.10.1.1
    • Component/s: Store
    • Labels:
      None

      Description

      If VirtualRandomAccessFile.close() is called more than once, which might happen in code that cleans up after errors, it will throw a NullPointerException. We should make close() idempotent so that it is more robust.

      1. d5960-1a.diff
        4 kB
        Knut Anders Hatlen

        Issue Links

          Activity

          Hide
          ASF subversion and git services added a comment -

          Commit 1509794 from Kathey Marsden in branch 'code/branches/10.8'
          [ https://svn.apache.org/r1509794 ]

          DERBY-5960 VirtualRandomAccessFile.close() is not idempotent

          Merge revision 1402111 from trunk.
          Contributed by Knut Anders Hatlen

          Show
          ASF subversion and git services added a comment - Commit 1509794 from Kathey Marsden in branch 'code/branches/10.8' [ https://svn.apache.org/r1509794 ] DERBY-5960 VirtualRandomAccessFile.close() is not idempotent Merge revision 1402111 from trunk. Contributed by Knut Anders Hatlen
          Hide
          ASF subversion and git services added a comment -

          Commit 1509763 from Kathey Marsden in branch 'code/branches/10.9'
          [ https://svn.apache.org/r1509763 ]

          DERBY-5960 VirtualRandomAccessFile.close() is not idempotent

          Merge revision 1402111 from trunk.
          Contributed by Knut Anders Hatlen

          Show
          ASF subversion and git services added a comment - Commit 1509763 from Kathey Marsden in branch 'code/branches/10.9' [ https://svn.apache.org/r1509763 ] DERBY-5960 VirtualRandomAccessFile.close() is not idempotent Merge revision 1402111 from trunk. Contributed by Knut Anders Hatlen
          Hide
          Kathey Marsden added a comment -

          temporarily reassign for backport.

          Show
          Kathey Marsden added a comment - temporarily reassign for backport.
          Hide
          Knut Anders Hatlen added a comment -

          Committed revision 1402111.

          Show
          Knut Anders Hatlen added a comment - Committed revision 1402111.
          Hide
          Knut Anders Hatlen added a comment -

          Attaching a fix, including a test case in VirtualFileTest.

          The patch simply makes close() stop nulling out the fields so that it won't run into a NPE on subsequent executions.

          (I preferred that approach to adding extra null checks in close(), as it allows the code to be slightly shorter/simpler. The advantage of nulling the fields and adding extra checks would be that the objects references by the fields would be eligible for gc earlier if the VirtualRandomAccessFile instance itself was still referenced after close(). I believe that this is not the case in normal use of VRAF. And even if it is used that way, there's not much to gain since the big data structures (the byte arrays) in those instances are already freed. So adding extra code to optimize for that case didn't seem worthwhile.)

          I also used the opportunity to fix a typo in VirtualFile and make some of the fields in VirtualRandomAccessFile final.

          All the regression tests ran cleanly with the patch.

          Show
          Knut Anders Hatlen added a comment - Attaching a fix, including a test case in VirtualFileTest. The patch simply makes close() stop nulling out the fields so that it won't run into a NPE on subsequent executions. (I preferred that approach to adding extra null checks in close(), as it allows the code to be slightly shorter/simpler. The advantage of nulling the fields and adding extra checks would be that the objects references by the fields would be eligible for gc earlier if the VirtualRandomAccessFile instance itself was still referenced after close(). I believe that this is not the case in normal use of VRAF. And even if it is used that way, there's not much to gain since the big data structures (the byte arrays) in those instances are already freed. So adding extra code to optimize for that case didn't seem worthwhile.) I also used the opportunity to fix a typo in VirtualFile and make some of the fields in VirtualRandomAccessFile final. All the regression tests ran cleanly with the patch.

            People

            • Assignee:
              Knut Anders Hatlen
              Reporter:
              Knut Anders Hatlen
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development