You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Frédéric Hannes (Jira)" <ji...@apache.org> on 2023/11/10 09:41:00 UTC

[jira] [Created] (IO-821) commons-io 2.15.0 breaks backwards compatibility for PathUtils.fileContentEquals

Frédéric Hannes created IO-821:
----------------------------------

             Summary: commons-io 2.15.0 breaks backwards compatibility for PathUtils.fileContentEquals
                 Key: IO-821
                 URL: https://issues.apache.org/jira/browse/IO-821
             Project: Commons IO
          Issue Type: Bug
          Components: Utilities
    Affects Versions: 2.15.0
            Reporter: Frédéric Hannes


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}}|https://github.com/apache/commons-io/commit/dd93554b692cabe884e7a097e431f475397a3b48#diff-4162512d2bb8d032482958d8dabacc1c2398e95597a49fa5b0fc02aabc8717d6R769], where the comparison of input streams through {{IOUtils.contentEquals()}} is replaced with {{RandomAccessFile.contentEquals()}}.

The issue occurs in {{RandomAccessFileMode.create()}}, where [{{Path.toFile()}}|https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html#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|https://docs.oracle.com/javase/8/docs/technotes/guides/io/fsp/zipfilesystemprovider.html]. 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.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)