Uploaded image for project: 'Commons Configuration'
  1. Commons Configuration
  2. CONFIGURATION-712

FileHandlerReloadingDetector Does Not Correctly Initialize File Last Modified

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3
    • Fix Version/s: 2.4
    • Component/s: File reloading
    • Labels:
      None

      Description

      FileHandlerReloadingDetector declares the following method:

       

      150    @Override
      151    public boolean isReloadingRequired()
      152    {
      153        long now = System.currentTimeMillis();
      154        if (now >= lastChecked + getRefreshDelay())
      155        {
      156            lastChecked = now;
      157
      158            long modified = getLastModificationDate();
      159            if (modified > 0)
      160            {
      161                if (lastModified == 0)
      162                {
      163                    // initialization
      164                    updateLastModified(modified);
      165                }
      166                else
      167                {
      168                    if (modified != lastModified)
      169                    {
      170                        return true;
      171                    }
      172                }
      173            }
      174        }
      175
      176        return false;
      177    }
      

       

      During initialization of FileHandlerReloadingDetector, lastModified is never instantiated, so the first time isReloadingRequired() is invoked lastModified will be 0.

       

      This results in two issues:

       

      Test #1

      • Scenario Steps 
        1. Initialize ReloadingFileBasedConfigurationBuilder without invoking builder.getConfiguration()
        2. Wait longer than refreshDelay
        3. Invoke builder.getReloadingController().checkForReloading(null) to notify the FileHandlerReloadingDetector to check for reload
        4. Invoke bulider.getConfiguration()
        5. Update the properties file
        6. Wait longer than refreshDelay
        7. Invoke builder.getReloadingController().checkForReloading(null) to notify the FileHandlerReloadingDetector to check for reload
        8. Invoke bulider.getConfiguration()
      • Result - the Configuration does not have the updated value.

       

      Test #2

      • Scenario Steps 
        1. Initialize ReloadingFileBasedConfigurationBuilder without invoking builder.getConfiguration()
        2. Invoke bulider.getConfiguration()
        3. Update the properties file
        4. Wait longer than refreshDelay
        5. Invoke builder.getReloadingController().checkForReloading(null) to notify the FileHandlerReloadingDetector to check for reload
        6. Invoke bulider.getConfiguration()
        7. Update the properties file
        8. Wait longer than refreshDelay
        9. Invoke builder.getReloadingController().checkForReloading(null) to notify the FileHandlerReloadingDetector to check for reload
        10. Invoke bulider.getConfiguration()
      • Result - For the first two invocations, the Configuration is not updated. One the third invocation of builder.getConfiguration() the property is updated to the new value.

       

      As potential solution, the constructor of FileHandlerReloadingDetector should either call isReloadingRequired() or updateLastModified(getLastModificationDate()) to initialize the lastModified instance variable to the file current lastModified value.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              rllndhbb Rolland Hobbie
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 24h
                24h
                Remaining:
                Remaining Estimate - 24h
                24h
                Logged:
                Time Spent - Not Specified
                Not Specified