LOG4J2-435 attempt to fix failing test on unix

Sorting seems to be broken. I suspect this is causing the test failures.
Try taking a snapshot of BasicFileAttributes values during initial file
tree walk instead of just keeping a reference to the attributes object
itself: this object may just be a view whose values change during the
tree walk.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/2855e970
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/2855e970
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/2855e970

Branch: refs/heads/LOG4J-1181
Commit: 2855e97054b39ba863e46c1accbe21f1e4a35ae6
Parents: 930cd8f
Author: rpopma <[email protected]>
Authored: Sun Nov 29 12:34:58 2015 +0900
Committer: rpopma <[email protected]>
Committed: Sun Nov 29 12:34:58 2015 +0900

----------------------------------------------------------------------
 .../rolling/action/PathWithAttributes.java      | 124 ++++++++++++++++++-
 1 file changed, 123 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2855e970/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathWithAttributes.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathWithAttributes.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathWithAttributes.java
index 88c460a..36833da 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathWithAttributes.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathWithAttributes.java
@@ -19,23 +19,45 @@ package 
org.apache.logging.log4j.core.appender.rolling.action;
 
 import java.nio.file.Path;
 import java.nio.file.attribute.BasicFileAttributes;
+import java.nio.file.attribute.FileTime;
 import java.util.Objects;
 
 /**
  * Tuple of a {@code Path} and {@code BasicFileAttributes}, used for sorting.
  */
-public class PathWithAttributes {
+public class PathWithAttributes implements BasicFileAttributes {
 
     private final Path path;
     private final BasicFileAttributes attributes;
+    private final FileTime lastModifiedTime;
+    private final FileTime lastAccessTime;
+    private final FileTime creationTime;
+    private final boolean regularFile;
+    private final boolean directory;
+    private final boolean symbolicLink;
+    private final boolean other;
+    private final long size;
+    private final Object fileKey;
 
     public PathWithAttributes(final Path path, final BasicFileAttributes 
attributes) {
         this.path = Objects.requireNonNull(path, "path");
         this.attributes = Objects.requireNonNull(attributes, "attributes");
+        
+        // take snapshot of attributes, it may be just a view whose values 
change
+        this.lastModifiedTime = attributes.lastModifiedTime();
+        this.lastAccessTime = attributes.lastAccessTime();
+        this.creationTime = attributes.creationTime();
+        this.regularFile = attributes.isRegularFile();
+        this.directory = attributes.isDirectory();
+        this.symbolicLink = attributes.isSymbolicLink();
+        this.other = attributes.isOther();
+        this.size = attributes.size();
+        this.fileKey = attributes.fileKey();
     }
 
     /**
      * Returns the path.
+     * 
      * @return the path
      */
     public Path getPath() {
@@ -44,9 +66,109 @@ public class PathWithAttributes {
 
     /**
      * Returns the attributes.
+     * 
      * @return the attributes
      */
     public BasicFileAttributes getAttributes() {
+        return this;
+    }
+
+    /**
+     * Returns the original attributes object.
+     * 
+     * @return the original attributes object
+     */
+    public BasicFileAttributes getOriginalAttributes() {
         return attributes;
     }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.nio.file.attribute.BasicFileAttributes#lastModifiedTime()
+     */
+    @Override
+    public FileTime lastModifiedTime() {
+        return lastModifiedTime;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.nio.file.attribute.BasicFileAttributes#lastAccessTime()
+     */
+    @Override
+    public FileTime lastAccessTime() {
+        return lastAccessTime;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.nio.file.attribute.BasicFileAttributes#creationTime()
+     */
+    @Override
+    public FileTime creationTime() {
+        return creationTime;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.nio.file.attribute.BasicFileAttributes#isRegularFile()
+     */
+    @Override
+    public boolean isRegularFile() {
+        return regularFile;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.nio.file.attribute.BasicFileAttributes#isDirectory()
+     */
+    @Override
+    public boolean isDirectory() {
+        return directory;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.nio.file.attribute.BasicFileAttributes#isSymbolicLink()
+     */
+    @Override
+    public boolean isSymbolicLink() {
+        return symbolicLink;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.nio.file.attribute.BasicFileAttributes#isOther()
+     */
+    @Override
+    public boolean isOther() {
+        return other;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.nio.file.attribute.BasicFileAttributes#size()
+     */
+    @Override
+    public long size() {
+        return size;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.nio.file.attribute.BasicFileAttributes#fileKey()
+     */
+    @Override
+    public Object fileKey() {
+        return fileKey;
+    }
 }

Reply via email to