RFR: 8303832: Use enhanced-for cycle instead of Enumeration in JceKeyStore
Michael StJohns
mstjohns at comcast.net
Wed Mar 8 20:15:12 UTC 2023
On 3/8/2023 2:19 PM, Andrey Turbanov wrote:
> java.util.Enumeration is a legacy interface from java 1.0.
> There is couple of places with cycles which use it to iterate over collections. We can replace this manual cycle with enchanced-for, which is shorter and easier to read.
>
> -------------
>
> Commit messages:
> - [PATCH] Use enhanced-for cycle instead of Enumeration in JceKeyStore
>
> Changes: https://git.openjdk.org/jdk/pull/12930/files
> Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=12930&range=00
> Issue: https://bugs.openjdk.org/browse/JDK-8303832
> Stats: 8 lines in 1 file changed: 0 ins; 5 del; 3 mod
> Patch: https://git.openjdk.org/jdk/pull/12930.diff
> Fetch: git fetch https://git.openjdk.org/jdk pull/12930/head:pull/12930
>
> PR: https://git.openjdk.org/jdk/pull/12930
Perhaps updating the various Object assignments to be somewhat more
typed as well would be helpful? E.g.
private static interface Entry { Instant getInstant(); } // or maybe
abstract? All "Date" objects end up as java.time.Instant
private static final class SecretKeyEntry implements Entry { ... } //
and the same for PrivateKeyEntry and SecretKeyEntry
private Hashtable<String, Entry> = new Hashtable<>();
Entry entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
Etc.
Last note - perhaps modify the internal storage of the creation date
from java.util.Date to a java.time.Instant?
createInstant = Instant.now().truncatedTo(ChronoUnit.SECONDS);
That makes the core of engineGetCreationDate to be something like:
return Date.from (entry.getInstant()); // Instant is immutable, Date is
not.
More information about the security-dev
mailing list