Skip to content

Commit 9ac204d

Browse files
author
Gary Gregory
committed
Inline single use local vars.
Use "require" prefix for private method like Objects.require*. Normalize spelling. Fix spelling. Remove dead comments.
1 parent 817bdf1 commit 9ac204d

2 files changed

Lines changed: 13 additions & 18 deletions

File tree

src/main/java/org/apache/commons/io/FileUtils.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,10 +1226,7 @@ public static boolean directoryContains(final File directory, final File child)
12261226
}
12271227

12281228
// Canonicalize paths (normalizes relative paths)
1229-
final String canonicalParent = directory.getCanonicalPath();
1230-
final String canonicalChild = child.getCanonicalPath();
1231-
1232-
return FilenameUtils.directoryContains(canonicalParent, canonicalChild);
1229+
return FilenameUtils.directoryContains(directory.getCanonicalPath(), child.getCanonicalPath());
12331230
}
12341231

12351232
/**

src/main/java/org/apache/commons/io/FilenameUtils.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
* Most methods on this class are designed to work the same on both Unix and Windows.
4343
* Those that don't include 'System', 'Unix' or 'Windows' in their name.
4444
* <p>
45-
* Most methods recognise both separators (forward and back), and both
46-
* sets of prefixes. See the javadoc of each method for details.
45+
* Most methods recognize both separators (forward and back), and both
46+
* sets of prefixes. See the Javadoc of each method for details.
4747
* <p>
4848
* This class defines six components within a file name
4949
* (example C:\dev\project\file.txt):
@@ -359,7 +359,7 @@ private static String doNormalize(final String fileName, final char separator, f
359359
return null;
360360
}
361361

362-
failIfNullBytePresent(fileName);
362+
requireNonNullChars(fileName);
363363

364364
int size = fileName.length();
365365
if (size == 0) {
@@ -551,7 +551,6 @@ public static boolean directoryContains(final String canonicalParent, final Stri
551551
return IOCase.SYSTEM.checkStartsWith(canonicalChild, canonicalParent);
552552
}
553553

554-
//-----------------------------------------------------------------------
555554
/**
556555
* Converts all separators to the Unix separator of forward slash.
557556
*
@@ -591,7 +590,6 @@ public static String separatorsToSystem(final String path) {
591590
return isSystemWindows() ? separatorsToWindows(path) : separatorsToUnix(path);
592591
}
593592

594-
//-----------------------------------------------------------------------
595593
/**
596594
* Returns the length of the fileName prefix, such as <code>C:/</code> or <code>~/</code>.
597595
* <p>
@@ -789,11 +787,11 @@ public static String getPrefix(final String fileName) {
789787
return null;
790788
}
791789
if (len > fileName.length()) {
792-
failIfNullBytePresent(fileName + UNIX_SEPARATOR);
790+
requireNonNullChars(fileName + UNIX_SEPARATOR);
793791
return fileName + UNIX_SEPARATOR;
794792
}
795793
final String path = fileName.substring(0, len);
796-
failIfNullBytePresent(path);
794+
requireNonNullChars(path);
797795
return path;
798796
}
799797

@@ -873,7 +871,7 @@ private static String doGetPath(final String fileName, final int separatorAdd) {
873871
return EMPTY_STRING;
874872
}
875873
final String path = fileName.substring(prefix, endIndex);
876-
failIfNullBytePresent(path);
874+
requireNonNullChars(path);
877875
return path;
878876
}
879877

@@ -990,7 +988,7 @@ public static String getName(final String fileName) {
990988
if (fileName == null) {
991989
return null;
992990
}
993-
failIfNullBytePresent(fileName);
991+
requireNonNullChars(fileName);
994992
final int index = indexOfLastSeparator(fileName);
995993
return fileName.substring(index + 1);
996994
}
@@ -1001,7 +999,7 @@ public static String getName(final String fileName) {
1001999
* This may be used for poison byte attacks.
10021000
* @param path the path to check
10031001
*/
1004-
private static void failIfNullBytePresent(final String path) {
1002+
private static void requireNonNullChars(final String path) {
10051003
final int len = path.length();
10061004
for (int i = 0; i < len; i++) {
10071005
if (path.charAt(i) == 0) {
@@ -1116,7 +1114,7 @@ public static String removeExtension(final String fileName) {
11161114
if (fileName == null) {
11171115
return null;
11181116
}
1119-
failIfNullBytePresent(fileName);
1117+
requireNonNullChars(fileName);
11201118

11211119
final int index = indexOfExtension(fileName);
11221120
if (index == NOT_FOUND) {
@@ -1240,7 +1238,7 @@ public static boolean isExtension(final String fileName, final String extension)
12401238
if (fileName == null) {
12411239
return false;
12421240
}
1243-
failIfNullBytePresent(fileName);
1241+
requireNonNullChars(fileName);
12441242

12451243
if (extension == null || extension.isEmpty()) {
12461244
return indexOfExtension(fileName) == NOT_FOUND;
@@ -1265,7 +1263,7 @@ public static boolean isExtension(final String fileName, final String... extensi
12651263
if (fileName == null) {
12661264
return false;
12671265
}
1268-
failIfNullBytePresent(fileName);
1266+
requireNonNullChars(fileName);
12691267

12701268
if (extensions == null || extensions.length == 0) {
12711269
return indexOfExtension(fileName) == NOT_FOUND;
@@ -1295,7 +1293,7 @@ public static boolean isExtension(final String fileName, final Collection<String
12951293
if (fileName == null) {
12961294
return false;
12971295
}
1298-
failIfNullBytePresent(fileName);
1296+
requireNonNullChars(fileName);
12991297

13001298
if (extensions == null || extensions.isEmpty()) {
13011299
return indexOfExtension(fileName) == NOT_FOUND;

0 commit comments

Comments
 (0)