Skip to content
Permalink
Browse files
8274050: Unnecessary Vector usage in javax.crypto
Reviewed-by: valeriep
  • Loading branch information
turbanoff authored and Valerie Peng committed Sep 29, 2021
1 parent 97b2874 commit 79cebe2c1b1e7f43377633b62c970528cac0a786
Showing 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 @@ CryptoPermissions getMinimum(CryptoPermissions other) {
*/
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 @@ private CryptoPermission[] getMinimum(PermissionCollection thisPc,
(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,34 +361,32 @@ private CryptoPermission[] getMinimum(PermissionCollection thisPc,
*/
private CryptoPermission[] getMinimum(int maxKeySize,
PermissionCollection pc) {
Vector<CryptoPermission> permVector = new Vector<>(1);
ArrayList<CryptoPermission> permList = new ArrayList<>(1);

Enumeration<Permission> enum_ = pc.elements();

while (enum_.hasMoreElements()) {
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()));
}
}
}

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,24 +255,23 @@ private CryptoPermissionEntry parsePermissionEntry(
// 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");
}
}
}

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 @@ else if (expect.equalsIgnoreCase("permission type")) {
}

CryptoPermission[] getPermissions() {
Vector<CryptoPermission> result = new Vector<>();
ArrayList<CryptoPermission> result = new ArrayList<>();

Enumeration<GrantEntry> grantEnum = grantEntries.elements();
while (grantEnum.hasMoreElements()) {
@@ -469,16 +469,16 @@ CryptoPermission[] getPermissions() {
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 @@ CryptoPermission[] getPermissions() {
}
}

CryptoPermission[] ret = new CryptoPermission[result.size()];
result.copyInto(ret);

return ret;
return result.toArray(new CryptoPermission[0]);
}

private boolean isConsistent(String alg, String exemptionMechanism,

1 comment on commit 79cebe2

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 79cebe2 Sep 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.