mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8274050: Unnecessary Vector usage in javax.crypto
Reviewed-by: valeriep
This commit is contained in:
parent
97b28742b4
commit
79cebe2c1b
2 changed files with 22 additions and 29 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -26,9 +26,9 @@
|
|||
package javax.crypto;
|
||||
|
||||
import java.security.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.io.Serializable;
|
||||
|
@ -307,7 +307,7 @@ implements Serializable {
|
|||
*/
|
||||
private CryptoPermission[] getMinimum(PermissionCollection thisPc,
|
||||
PermissionCollection thatPc) {
|
||||
Vector<CryptoPermission> permVector = new Vector<>(2);
|
||||
ArrayList<CryptoPermission> permList = new ArrayList<>(2);
|
||||
|
||||
Enumeration<Permission> thisPcPermissions = thisPc.elements();
|
||||
|
||||
|
@ -334,18 +334,16 @@ implements Serializable {
|
|||
(CryptoPermission)thatPcPermissions.nextElement();
|
||||
|
||||
if (thatCp.implies(thisCp)) {
|
||||
permVector.addElement(thisCp);
|
||||
permList.add(thisCp);
|
||||
break;
|
||||
}
|
||||
if (thisCp.implies(thatCp)) {
|
||||
permVector.addElement(thatCp);
|
||||
permList.add(thatCp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CryptoPermission[] ret = new CryptoPermission[permVector.size()];
|
||||
permVector.copyInto(ret);
|
||||
return ret;
|
||||
return permList.toArray(new CryptoPermission[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -363,7 +361,7 @@ implements Serializable {
|
|||
*/
|
||||
private CryptoPermission[] getMinimum(int maxKeySize,
|
||||
PermissionCollection pc) {
|
||||
Vector<CryptoPermission> permVector = new Vector<>(1);
|
||||
ArrayList<CryptoPermission> permList = new ArrayList<>(1);
|
||||
|
||||
Enumeration<Permission> enum_ = pc.elements();
|
||||
|
||||
|
@ -371,16 +369,16 @@ implements Serializable {
|
|||
CryptoPermission cp =
|
||||
(CryptoPermission)enum_.nextElement();
|
||||
if (cp.getMaxKeySize() <= maxKeySize) {
|
||||
permVector.addElement(cp);
|
||||
permList.add(cp);
|
||||
} else {
|
||||
if (cp.getCheckParam()) {
|
||||
permVector.addElement(
|
||||
permList.add(
|
||||
new CryptoPermission(cp.getAlgorithm(),
|
||||
maxKeySize,
|
||||
cp.getAlgorithmParameterSpec(),
|
||||
cp.getExemptionMechanism()));
|
||||
} else {
|
||||
permVector.addElement(
|
||||
permList.add(
|
||||
new CryptoPermission(cp.getAlgorithm(),
|
||||
maxKeySize,
|
||||
cp.getExemptionMechanism()));
|
||||
|
@ -388,9 +386,7 @@ implements Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
CryptoPermission[] ret = new CryptoPermission[permVector.size()];
|
||||
permVector.copyInto(ret);
|
||||
return ret;
|
||||
return permList.toArray(new CryptoPermission[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -26,6 +26,7 @@
|
|||
package javax.crypto;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
|
@ -254,15 +255,15 @@ final class CryptoPolicyParser {
|
|||
// AlgorithmParameterSpec class name.
|
||||
String algParamSpecClassName = match("quoted string");
|
||||
|
||||
Vector<Integer> paramsV = new Vector<>(1);
|
||||
ArrayList<Integer> paramsV = new ArrayList<>(1);
|
||||
while (peek(",")) {
|
||||
match(",");
|
||||
if (peek("number")) {
|
||||
paramsV.addElement(match());
|
||||
paramsV.add(match());
|
||||
} else {
|
||||
if (peek("*")) {
|
||||
match("*");
|
||||
paramsV.addElement(Integer.MAX_VALUE);
|
||||
paramsV.add(Integer.MAX_VALUE);
|
||||
} else {
|
||||
throw new ParsingException(st.lineno(),
|
||||
"Expecting an integer");
|
||||
|
@ -270,8 +271,7 @@ final class CryptoPolicyParser {
|
|||
}
|
||||
}
|
||||
|
||||
Integer[] params = new Integer[paramsV.size()];
|
||||
paramsV.copyInto(params);
|
||||
Integer[] params = paramsV.toArray(new Integer[0]);
|
||||
|
||||
e.checkParam = true;
|
||||
e.algParamSpec = getInstance(algParamSpecClassName, params);
|
||||
|
@ -458,7 +458,7 @@ final class CryptoPolicyParser {
|
|||
}
|
||||
|
||||
CryptoPermission[] getPermissions() {
|
||||
Vector<CryptoPermission> result = new Vector<>();
|
||||
ArrayList<CryptoPermission> result = new ArrayList<>();
|
||||
|
||||
Enumeration<GrantEntry> grantEnum = grantEntries.elements();
|
||||
while (grantEnum.hasMoreElements()) {
|
||||
|
@ -469,16 +469,16 @@ final class CryptoPolicyParser {
|
|||
CryptoPermissionEntry pe = permEnum.nextElement();
|
||||
if (pe.cryptoPermission.equals(
|
||||
"javax.crypto.CryptoAllPermission")) {
|
||||
result.addElement(CryptoAllPermission.INSTANCE);
|
||||
result.add(CryptoAllPermission.INSTANCE);
|
||||
} else {
|
||||
if (pe.checkParam) {
|
||||
result.addElement(new CryptoPermission(
|
||||
result.add(new CryptoPermission(
|
||||
pe.alg,
|
||||
pe.maxKeySize,
|
||||
pe.algParamSpec,
|
||||
pe.exemptionMechanism));
|
||||
} else {
|
||||
result.addElement(new CryptoPermission(
|
||||
result.add(new CryptoPermission(
|
||||
pe.alg,
|
||||
pe.maxKeySize,
|
||||
pe.exemptionMechanism));
|
||||
|
@ -487,10 +487,7 @@ final class CryptoPolicyParser {
|
|||
}
|
||||
}
|
||||
|
||||
CryptoPermission[] ret = new CryptoPermission[result.size()];
|
||||
result.copyInto(ret);
|
||||
|
||||
return ret;
|
||||
return result.toArray(new CryptoPermission[0]);
|
||||
}
|
||||
|
||||
private boolean isConsistent(String alg, String exemptionMechanism,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue