RFR: 8274050: Unnecessary Vector usage in javax.crypto
Andrey Turbanov
github.com+741251+turbanoff at openjdk.java.net
Tue Sep 21 07:34:28 UTC 2021
On Wed, 8 Sep 2021 02:10:36 GMT, David Schlosnagle <github.com+54594+schlosna at openjdk.org> wrote:
>> In [JDK-8268873](https://bugs.openjdk.java.net/browse/JDK-8268873) I missed a few places, where Vector could be replaced with ArrayList.
>> Usage of thread-safe collection `Vector` is unnecessary. It's recommended to use `ArrayList` if a thread-safe implementation is not needed.
>
> src/java.base/share/classes/javax/crypto/CryptoPermissions.java line 348:
>
>> 346: CryptoPermission[] ret = new CryptoPermission[permVector.size()];
>> 347: permVector.copyInto(ret);
>> 348: return ret;
>
> Should this return the result of `toArray` for safety (though it is sized correctly so per API should return the same `ret` array).
>
> Suggestion:
>
> CryptoPermission[] ret = new CryptoPermission[permList.size()];
> return permList.toArray(ret);
>
>
> Separate perf nit would be to use size zero array as arg to `toArray` per https://shipilev.net/blog/2016/arrays-wisdom-ancients/
>
> Suggestion:
>
> return permList.toArray(new CryptoPermission[0]);
Thank for suggestion. Updated.
-------------
PR: https://git.openjdk.java.net/jdk/pull/5261
More information about the security-dev
mailing list