Uploaded image for project: 'Commons IO'
  1. Commons IO
  2. IO-821

2.15.0 breaks backwards compatibility in PathUtils.fileContentEquals for the Zip file system

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.15.0
    • 2.15.1
    • Utilities
    • None

    Description

      Relevant change

      Version 2.15.0 of commons-io features performance improvements by ggregory  for PathUtils.fileContextEquals() as listed in the changelog:

      Improve performance of PathUtils.fileContentEquals(Path, Path, LinkOption[], OpenOption[]) by about 60%, see PathUtilsContentEqualsBenchmark.

      The relevant change occurs in commit dd93554b, where the comparison of input streams through IOUtils.contentEquals() is replaced with RandomAccessFile.contentEquals().

      Issue description

      The issue occurs in RandomAccessFileMode.create(), where Path.toFile() is called. This method like many in Path, can throw an UnsupportedOperationException if it is not implemented by the filesystem provider.

      In our particular case, we compare files from a zip archive with files on disk using the zip filesystem provider that was introduced in Java 7. The class jdk.nio.zipfs.ZipPath does not implement Path.toFile() and therefore throws an UnsupportedOperationException.

      Though it does not seem unreasonable to limit the functionality of this method to a specific subset of Path implementations, this does seem to be a substantial breaking change in behavior of an existing method, which I am not sure was intentional.

      As a workaround to resolve the issue without downgrading, we now call IOUtils.contentEquals() directly.

      Attachments

        Activity

          People

            Unassigned Unassigned
            fhannes Frédéric Hannes
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: