Skip to content

Commit 748eef8

Browse files
committed
PR: IO-567
- Replaced NtfsAdsNameException with IllegalArgumentException. - Fixed Javadoc ("Output will be the same irrespective of the machine...")
2 parents 947c01f + 72d0053 commit 748eef8

2 files changed

Lines changed: 14 additions & 27 deletions

File tree

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -714,28 +714,30 @@ public static int indexOfLastSeparator(final String filename) {
714714
* {@link #indexOfLastSeparator(String)} which will handle a file in either Unix or Windows format.
715715
* </p>
716716
* <p>
717-
* The output will be the same irrespective of the machine that the code is running on.
717+
* The output will be the same irrespective of the machine that the code is running on, with the
718+
* exception of a possible {@link IllegalArgumentException} on Windows (see below).
718719
* </p>
719720
* <b>Note:</b> This method used to have a hidden problem for names like "foo.exe:bar.txt".
720721
* In this case, the name wouldn't be the name of a file, but the identifier of an
721722
* alternate data stream (bar.txt) on the file foo.exe. The method used to return
722723
* ".txt" here, which would be misleading. Commons IO 2.7, and later versions, are throwing
723-
* at {@link NtfsAdsNameException} for names like this.
724+
* an {@link IllegalArgumentException} for names like this.
724725
*
725726
* @param filename
726727
* the filename to find the last extension separator in, null returns -1
727728
* @return the index of the last extension separator character, or -1 if there is no such character
728-
* @throws NtfsAdsNameException The filename argument
729+
* @throws IllegalArgumentException <b>Windows only:/b> The filename parameter is, in fact,
730+
* the identifier of an Alternate Data Stream, for example "foo.exe:bar.txt".
729731
*/
730-
public static int indexOfExtension(final String filename) throws NtfsAdsNameException {
732+
public static int indexOfExtension(final String filename) throws IllegalArgumentException {
731733
if (filename == null) {
732734
return NOT_FOUND;
733735
}
734736
if (isSystemWindows()) {
735737
// Special handling for NTFS ADS: Don't accept colon in the filename.
736738
final int offset = filename.indexOf(':', getAdsCriticalOffset(filename));
737739
if (offset != -1) {
738-
throw new NtfsAdsNameException("NTFS ADS separator (':') in filename is forbidden.");
740+
throw new IllegalArgumentException("NTFS ADS separator (':') in filename is forbidden.");
739741
}
740742
}
741743
final int extensionPos = filename.lastIndexOf(EXTENSION_SEPARATOR);
@@ -1039,20 +1041,23 @@ public static String getBaseName(final String filename) {
10391041
* a/b/c --&gt; ""
10401042
* </pre>
10411043
* <p>
1042-
* The output will be the same irrespective of the machine that the code is running on.
1044+
* The output will be the same irrespective of the machine that the code is running on, with the
1045+
* exception of a possible {@link IllegalArgumentException} on Windows (see below).
1046+
* </p>
1047+
* <p>
10431048
* <b>Note:</b> This method used to have a hidden problem for names like "foo.exe:bar.txt".
10441049
* In this case, the name wouldn't be the name of a file, but the identifier of an
10451050
* alternate data stream (bar.txt) on the file foo.exe. The method used to return
10461051
* ".txt" here, which would be misleading. Commons IO 2.7, and later versions, are throwing
1047-
* at {@link NtfsAdsNameException} for names like this.
1052+
* an {@link IllegalArgumentException} for names like this.
10481053
*
10491054
* @param filename the filename to retrieve the extension of.
10501055
* @return the extension of the file or an empty string if none exists or {@code null}
10511056
* if the filename is {@code null}.
1052-
* @throws NtfsAdsNameException <b>Windows only:/b> The filename parameter is, in fact,
1057+
* @throws IllegalArgumentException <b>Windows only:/b> The filename parameter is, in fact,
10531058
* the identifier of an Alternate Data Stream, for example "foo.exe:bar.txt".
10541059
*/
1055-
public static String getExtension(final String filename) throws NtfsAdsNameException {
1060+
public static String getExtension(final String filename) throws IllegalArgumentException {
10561061
if (filename == null) {
10571062
return null;
10581063
}

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

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)