Closed okey closed 11 months ago
Thanks for the contribution, @okey! I refactored your solution a bit to still plug in a comparator, but one that uses a static lastModified
property. As for cleanCache(long maxBytes, Comparator<File> fileComparator, StringBuilder sbuff)
, I don't think we want to deprecate it since there are still reasons users may want to sub their own Comparator
to sort the files in their cache.
@haileyajohnson Thanks for the refactor, if you're happy with using a static property then I think it's a good solution. ~Do you want to fix the test failures or shall I?~
Description of Changes
Java versions newer than 6 check that the sort invariant is maintained. If a cached file is modified during sort, then the modified time changes, violating the invariant and causing an exception to be thrown. Previously, this would have silently caused the resulting sort to be incorrect.
Neither of these results are ideal, but throwing an exception causes the cache cleanup to fail, which can lead to unexpectedly high cache usage.
A quick and nasty hack to revert to Java 6 behaviour is to insert
System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");
somewhere, but it is better to fix the sort completely.This PR caches the file modification times and looks them up during the sort.
PR Checklist