RFR: 8057113: (fs) Path should have a method to obtain the filename extension [v14]

Brian Burkhalter bpb at openjdk.org
Tue Jul 26 20:07:14 UTC 2022


On Tue, 26 Jul 2022 19:44:39 GMT, Roger Riggs <rriggs at openjdk.org> wrote:

>> Brian Burkhalter has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 18 additional commits since the last revision:
>> 
>>  - 8057113: Revert return type back to a nullable-String; update test
>>  - Merge
>>  - 8057113: Remove extensions() test method; add threthree new test cases
>>  - 8057113: Revert excision of wild cards from imports
>>  - 8057113: Add class level apiNote; improve getExtension() specification; remove hasExtension() and replaceExtension()
>>  - Merge
>>  - 8057113: Change @since annotation to 20
>>  - Merge
>>  - 8057113: Remove superfluous new Object[] statements from test
>>  - 8057113: Fix getExtension() commcents; improve hasExtension() implementation
>>  - ... and 8 more: https://git.openjdk.org/jdk/compare/74f81401...23ca3f10
>
> src/java.base/share/classes/java/nio/file/Path.java line 305:
> 
>> 303:         } else if (length == 2 &&
>> 304:                    !(fileNameString.charAt(0) == '.' ||
>> 305:                      fileNameString.charAt(1) != '.')) {
> 
> I would have coded it as:
> 
>    (length == 2 &&
>       fileNameString.charAt(0) != '.' &&
>       fileNameString.charat(1) == '.')) {
> 
> As a better match for the comment.

I had it that way originally but changed it thinking that fewer boolean expressions might need to be evaluated.

> test/jdk/java/nio/file/Path/Extensions.java line 64:
> 
>> 62:             {".profile.sh",    "sh"},
>> 63:             {"..foo",          "foo"},
>> 64:             {".....foo",       "foo"},
> 
> Duplicates the test  of line 53.

Check.

> test/jdk/java/nio/file/Path/Extensions.java line 77:
> 
>> 75:             {"x.zip",          "zip"},
>> 76:             {"y.gzip",         "gzip"},
>> 77:             {"z.jar",          "jar"},
> 
> Fewer test cases of a file with a 3 or 4 character extension would be fine too. 
> Algorithm-wise they are all the same but may give a warm fuzzy that a favorite extension is covered.

Indeed that's all it is. I doubt more than one test of an n-character extension is necessary.

-------------

PR: https://git.openjdk.org/jdk/pull/8066


More information about the nio-dev mailing list