[GRADLE-3369] Inconsistent behavior of FileTreeElement getSize/getLastModified methods Created: 05/Dec/15  Updated: 17/Feb/16  Resolved: 17/Feb/16

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: 2.11-rc-1

Type: Bug
Reporter: Sterling Greene Assignee: Lari Hotari
Resolution: Fixed Votes: 0

Known Issue Of:

 Description   

Depending on which version of the JDK you run Gradle with, any method that receives a FileTreeElement (mainly FileTree/FileCollection visit and eachFile FileCopyDetails) could see different behavior when calling getSize and getLastModified methods.

For JDK6, Gradle will usually return the size and last modified time of the underlying file at the time it is asked for. Any subsequent calls will return the same cached value.

For JDK7+, Gradle will usually return the size and last modified time of the underlying file when the file's parent has been visited. Any subsequent calls will return the same cached value.

In some cases, changes to the file will be reflected every time when calling getSize or getLastModified.

This inconsistency could cause problems if a task modifies files while visiting them and expects to see those changes reflected in the FileVisitDetails/FileTreeElement/FileCopyDetails getSize or getLastModified properties. This is uncommon behavior in most builds.

We plan to make this behavior consistent by always caching these values when the parent is visited. If you never want to see the cached values, we recommend using getFile().size() or getFile().lastModified() instead. This goes directly to the underlying file.



 Comments   
Comment by Mark Vieira (Inactive) [ 17/Feb/16 ]

Lari, did this get fixed in 2.11? Can we mark this as resolved?

Generated at Wed Jun 30 12:47:00 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.