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

AbstractHandler allows blind rewriting of existing complex obs file

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Code Review (Initial)
    • Priority: Should
    • Resolution: Unresolved
    • Affects Version/s: Platform 1.10.5, Platform 1.11.8, Platform 1.12.1, Platform 2.0.5, Core 2.1.0
    • Fix Version/s: Platform 1.11.10
    • Component/s: None
    • Complexity:
      Medium

      Description

      AbstractHandler#getOutputFileToWrite(Obs) is the method that provides the File instance to write to when saving a complex data file to disk.
      It constructs the target file name to be used based on the obs 'title':

      String extension = getExtension(t);
      String title = obs.getComplexData().getTitle();
      ...
      outputfile = new File(dir, title + "." + extension);
      

      And if the outputfile already exists, then it works on a new file whose name is made unique with a two-digit suffix.

      This works only up to the 100th file:

      while (obs.getObsId() == null && outputfile.exists() && i < 100) { ...
      

      The 100th file will just be blindly overwritten.

      Overall the design of this method should be challenged, down to the way it retrieves the extension out of the filename (why not use Apache's FilenameUtils?)

      I suggest a complete rewriting that ensures that the provided File instance is properly named and safe to write to.


      Also see 'Core: Cannot purge anymore a complex obs that has lost its complex data'.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              ruhanga Nathan Ruhanga
              Reporter:
              mksd Dimitri R
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 2 days
                  2d