You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/11/01 21:46:00 UTC

[commons-io] branch master updated: [IO-634] Make getCause synchronized and use a Deque instead of Stack (#64)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


The following commit(s) were added to refs/heads/master by this push:
     new 421b9dc  [IO-634] Make getCause synchronized and use a Deque instead of Stack (#64)
421b9dc is described below

commit 421b9dc027da0f1582120cb59ec9b2ceebf85bc4
Author: Václav Haisman <vh...@gmail.com>
AuthorDate: Fri Nov 1 22:45:49 2019 +0100

    [IO-634] Make getCause synchronized and use a Deque instead of Stack (#64)
    
    * Fix "Non-synchronized override of synchronized method".
    
    * Replace synchronized Stack with unsynchronized Deque in FilenameUtils.
---
 src/main/java/org/apache/commons/io/FilenameUtils.java     | 9 +++++----
 src/main/java/org/apache/commons/io/TaggedIOException.java | 2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/FilenameUtils.java b/src/main/java/org/apache/commons/io/FilenameUtils.java
index 81d27df..cf7c7cf 100644
--- a/src/main/java/org/apache/commons/io/FilenameUtils.java
+++ b/src/main/java/org/apache/commons/io/FilenameUtils.java
@@ -18,11 +18,12 @@ package org.apache.commons.io;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Deque;
 import java.util.List;
-import java.util.Stack;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -1385,11 +1386,11 @@ public class FilenameUtils {
         boolean anyChars = false;
         int textIdx = 0;
         int wcsIdx = 0;
-        final Stack<int[]> backtrack = new Stack<>();
+        final Deque<int[]> backtrack = new ArrayDeque<>(wcs.length);
 
         // loop around a backtrack stack, to handle complex * matching
         do {
-            if (backtrack.size() > 0) {
+            if (!backtrack.isEmpty()) {
                 final int[] array = backtrack.pop();
                 wcsIdx = array[0];
                 textIdx = array[1];
@@ -1448,7 +1449,7 @@ public class FilenameUtils {
                 return true;
             }
 
-        } while (backtrack.size() > 0);
+        } while (!backtrack.isEmpty());
 
         return false;
     }
diff --git a/src/main/java/org/apache/commons/io/TaggedIOException.java b/src/main/java/org/apache/commons/io/TaggedIOException.java
index afa66cb..5c6f0f4 100644
--- a/src/main/java/org/apache/commons/io/TaggedIOException.java
+++ b/src/main/java/org/apache/commons/io/TaggedIOException.java
@@ -129,7 +129,7 @@ public class TaggedIOException extends IOExceptionWithCause {
      * @return wrapped exception
      */
     @Override
-    public IOException getCause() {
+    public synchronized IOException getCause() {
         return (IOException) super.getCause();
     }