RFR: 8274050: Unnecessary Vector usage in javax.crypto

David Schlosnagle github.com+54594+schlosna at openjdk.java.net
Tue Sep 21 07:34:26 UTC 2021


On Thu, 26 Aug 2021 06:19:49 GMT, Andrey Turbanov <github.com+741251+turbanoff 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]);

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

PR: https://git.openjdk.java.net/jdk/pull/5261



More information about the security-dev mailing list