Uploaded image for project: 'OpenMRS Core'
  1. OpenMRS Core
  2. TRUNK-5031

UpgradeUtil may not close a stream

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Should
    • Resolution: Fixed
    • Affects Version/s: Platform 1.12.0, Platform 1.11.7, Platform 2.0.0, Platform 2.0.1, Platform 2.0.2, Platform 2.0.5
    • Fix Version/s: Platform 2.1.2, Core 2.2.0
    • Component/s: None
    • Labels:
    • Complexity:
      Low

      Description

      UpgradeUtil.getConceptIdForUnits does not ensure that the FileInputStream it creates is closed in case of an exception.

      See

      https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/util/UpgradeUtil.java#L41-L43

      Solution:

      Use the try-with-resource statement

      http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html

      to ensure FileInputStream will be closed in any case.

      This issue is also reported by the sonar qube at

      https://ci.openmrs.org/sonar/drilldown/issues/1865?&rule=findbugs%3AOS_OPEN_STREAM&rule_sev=CRITICAL&severity=CRITICAL

      Furthermore, I suggest to use the try-with-resource on the PreparedStatement

      which are used multiple times in this class, such as

      https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/util/UpgradeUtil.java#L105

      This makes the code more concise (the final block with the select.close() could be removed).

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              judeniroshan Jude Niroshan
              Reporter:
              teleivo Ivo Ulrich
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: