From d5948be13f788fddbf384643ae6fbac6cca87a18 Mon Sep 17 00:00:00 2001 From: pascalschumacher Date: Thu, 26 Dec 2019 23:51:46 +0100 Subject: [PATCH] Use ArrayUtils#EMPTY_STRING_ARRAY instead of creating new empty String arrays. --- .../java/org/apache/commons/lang3/StringUtils.java | 10 +++++----- .../apache/commons/lang3/exception/ExceptionUtils.java | 4 ++-- .../org/apache/commons/lang3/text/StrTokenizer.java | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index d6298062c..44fba32dc 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -7507,7 +7507,7 @@ public class StringUtils { currentType = type; } list.add(new String(c, tokenStart, c.length - tokenStart)); - return list.toArray(new String[0]); + return list.toArray(ArrayUtils.EMPTY_STRING_ARRAY); } /** @@ -7735,7 +7735,7 @@ public class StringUtils { } } - return substrings.toArray(new String[0]); + return substrings.toArray(ArrayUtils.EMPTY_STRING_ARRAY); } // ----------------------------------------------------------------------- @@ -7923,7 +7923,7 @@ public class StringUtils { if (match || preserveAllTokens && lastMatch) { list.add(str.substring(start, i)); } - return list.toArray(new String[0]); + return list.toArray(ArrayUtils.EMPTY_STRING_ARRAY); } /** @@ -8022,7 +8022,7 @@ public class StringUtils { if (match || preserveAllTokens && lastMatch) { list.add(str.substring(start, i)); } - return list.toArray(new String[0]); + return list.toArray(ArrayUtils.EMPTY_STRING_ARRAY); } /** @@ -8835,7 +8835,7 @@ public class StringUtils { if (list.isEmpty()) { return null; } - return list.toArray(new String[0]); + return list.toArray(ArrayUtils.EMPTY_STRING_ARRAY); } /** diff --git a/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java b/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java index dd154e312..6550fd85d 100644 --- a/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java +++ b/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java @@ -274,7 +274,7 @@ public class ExceptionUtils { } frames.addAll(trace); } - return frames.toArray(new String[0]); + return frames.toArray(ArrayUtils.EMPTY_STRING_ARRAY); } /** @@ -325,7 +325,7 @@ public class ExceptionUtils { while (frames.hasMoreTokens()) { list.add(frames.nextToken()); } - return list.toArray(new String[0]); + return list.toArray(ArrayUtils.EMPTY_STRING_ARRAY); } /** diff --git a/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java b/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java index 97fae7d78..8a5c33c9b 100644 --- a/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java +++ b/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java @@ -604,10 +604,10 @@ public class StrTokenizer implements ListIterator, Cloneable { if (chars == null) { // still call tokenize as subclass may do some work final List split = tokenize(null, 0, 0); - tokens = split.toArray(new String[0]); + tokens = split.toArray(ArrayUtils.EMPTY_STRING_ARRAY); } else { final List split = tokenize(chars, 0, chars.length); - tokens = split.toArray(new String[0]); + tokens = split.toArray(ArrayUtils.EMPTY_STRING_ARRAY); } } }