No need to allocate empty String arrays over and over.
MODIFY
src/main/java/org/apache/commons/io/FilenameUtils.java
src/main/java/org/apache/commons/io/FilenameUtils.java
*/
public class FilenameUtils {
+ private static final String[] EMPTY_STRING_ARRAY = new String[0];
+
private static final String EMPTY_STRING = "";
private static final int NOT_FOUND = -1;
@@ -1494,7 +1496,7 @@ public static boolean wildcardMatch(final String fileName, final String wildcard
list.add(buffer.toString());
}
- return list.toArray(new String[0]);
+ return list.toArray(EMPTY_STRING_ARRAY);
}
/**
@@ -1577,7 +1579,7 @@ private static boolean isIPv6Address(final String inet6Address) {
} else if (inet6Address.startsWith("::") && !octetList.isEmpty()) {
octetList.remove(0);
}
- octets = octetList.toArray(new String[0]);
+ octets = octetList.toArray(EMPTY_STRING_ARRAY);
}
if (octets.length > IPV6_MAX_HEX_GROUPS) {
return false;

MODIFY
src/main/java/org/apache/commons/io/filefilter/IOFileFilter.java
src/main/java/org/apache/commons/io/filefilter/IOFileFilter.java
*/
public interface IOFileFilter extends FileFilter, FilenameFilter {
+ String[] EMPTY_STRING_ARRAY = new String[0];
+
/**
* Checks to see if the File should be accepted by this filter.
* <p>

MODIFY
src/main/java/org/apache/commons/io/filefilter/NameFileFilter.java
src/main/java/org/apache/commons/io/filefilter/NameFileFilter.java
@@ -126,7 +126,7 @@ public NameFileFilter(final List<String> names, final IOCase caseSensitivity) {
if (names == null) {
throw new IllegalArgumentException("The list of names must not be null");
}
- this.names = names.toArray(new String[0]);
+ this.names = names.toArray(EMPTY_STRING_ARRAY);
this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
}

MODIFY
src/main/java/org/apache/commons/io/filefilter/PrefixFileFilter.java
src/main/java/org/apache/commons/io/filefilter/PrefixFileFilter.java
@@ -134,7 +134,7 @@ public PrefixFileFilter(final List<String> prefixes, final IOCase caseSensitivit
if (prefixes == null) {
throw new IllegalArgumentException("The list of prefixes must not be null");
}
- this.prefixes = prefixes.toArray(new String[0]);
+ this.prefixes = prefixes.toArray(EMPTY_STRING_ARRAY);
this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
}

MODIFY
src/main/java/org/apache/commons/io/filefilter/SuffixFileFilter.java
src/main/java/org/apache/commons/io/filefilter/SuffixFileFilter.java
@@ -135,7 +135,7 @@ public SuffixFileFilter(final List<String> suffixes, final IOCase caseSensitivit
if (suffixes == null) {
throw new IllegalArgumentException("The list of suffixes must not be null");
}
- this.suffixes = suffixes.toArray(new String[0]);
+ this.suffixes = suffixes.toArray(EMPTY_STRING_ARRAY);
this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
}

MODIFY
src/main/java/org/apache/commons/io/filefilter/WildcardFileFilter.java
src/main/java/org/apache/commons/io/filefilter/WildcardFileFilter.java
@@ -134,7 +134,7 @@ public WildcardFileFilter(final List<String> wildcards, final IOCase caseSensiti
if (wildcards == null) {
throw new IllegalArgumentException("The wildcard list must not be null");
}
- this.wildcards = wildcards.toArray(new String[0]);
+ this.wildcards = wildcards.toArray(EMPTY_STRING_ARRAY);
this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
}

MODIFY
src/main/java/org/apache/commons/io/filefilter/WildcardFilter.java
src/main/java/org/apache/commons/io/filefilter/WildcardFilter.java
@@ -93,7 +93,7 @@ public WildcardFilter(final List<String> wildcards) {
if (wildcards == null) {
throw new IllegalArgumentException("The wildcard list must not be null");
}
- this.wildcards = wildcards.toArray(new String[0]);
+ this.wildcards = wildcards.toArray(EMPTY_STRING_ARRAY);
}
//-----------------------------------------------------------------------

No need to allocate empty String arrays over and over.