Skip to content

Commit 5185dbd

Browse files
turbanoffAlekseiEfimov
authored andcommittedAug 30, 2021
8273098: Unnecessary Vector usage in java.naming
Reviewed-by: aefimov, dfuchs
1 parent 276b07b commit 5185dbd

File tree

3 files changed

+28
-29
lines changed

3 files changed

+28
-29
lines changed
 

‎src/java.naming/share/classes/com/sun/jndi/ldap/LdapSchemaParser.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,7 +27,7 @@
2727

2828
import javax.naming.*;
2929
import javax.naming.directory.*;
30-
import java.util.Vector;
30+
import java.util.ArrayList;
3131

3232
/**
3333
* Netscape's 3.1 servers have some schema bugs:
@@ -519,7 +519,7 @@ private static final String[] readQDescrList(String string, int[] pos)
519519
throws NamingException {
520520

521521
int begin, end;
522-
Vector<String> values = new Vector<>(5);
522+
ArrayList<String> values = new ArrayList<>(5);
523523

524524
if (debug) {
525525
System.err.println("ReadQDescrList: pos="+pos[0]);
@@ -543,7 +543,7 @@ private static final String[] readQDescrList(String string, int[] pos)
543543
"' at begin=" + begin + " end =" + end);
544544
}
545545

546-
values.addElement(one[0]);
546+
values.add(one[0]);
547547
skipWhitespace(string, pos);
548548
begin = pos[0];
549549
}
@@ -552,7 +552,7 @@ private static final String[] readQDescrList(String string, int[] pos)
552552

553553
String[] answer = new String[values.size()];
554554
for (int i = 0; i < answer.length; i++) {
555-
answer[i] = values.elementAt(i);
555+
answer[i] = values.get(i);
556556
}
557557
return answer;
558558
}
@@ -613,7 +613,7 @@ private static final String[] readOIDs(String string, int[] pos)
613613

614614
int begin, cur, end;
615615
String oidName = null;
616-
Vector<String> values = new Vector<>(5);
616+
ArrayList<String> values = new ArrayList<>(5);
617617

618618
if (debug) {
619619
System.err.println("ReadOIDList: pos="+pos[0]);
@@ -641,7 +641,7 @@ private static final String[] readOIDs(String string, int[] pos)
641641
System.err.println("ReadOIDList: found '" + oidName +
642642
"' at begin=" + begin + " end =" + end);
643643
}
644-
values.addElement(oidName);
644+
values.add(oidName);
645645
pos[0] = cur + 1;
646646
skipWhitespace(string, pos);
647647
begin = pos[0];
@@ -656,13 +656,13 @@ private static final String[] readOIDs(String string, int[] pos)
656656

657657
int wsBegin = findTrailingWhitespace(string, end - 1);
658658
oidName = string.substring(begin, wsBegin);
659-
values.addElement(oidName);
659+
values.add(oidName);
660660

661661
pos[0] = end+1;
662662

663663
String[] answer = new String[values.size()];
664664
for (int i = 0; i < answer.length; i++) {
665-
answer[i] = values.elementAt(i);
665+
answer[i] = values.get(i);
666666
}
667667
return answer;
668668
}

‎src/java.naming/share/classes/com/sun/jndi/ldap/Obj.java

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -38,9 +38,9 @@
3838
import java.io.ObjectStreamClass;
3939
import java.io.InputStream;
4040

41+
import java.util.ArrayList;
4142
import java.util.Base64;
4243
import java.util.Hashtable;
43-
import java.util.Vector;
4444
import java.util.StringTokenizer;
4545

4646
import java.lang.reflect.Proxy;
@@ -205,13 +205,13 @@ private static String[] getCodebases(Attribute codebaseAttr) throws
205205
} else {
206206
StringTokenizer parser =
207207
new StringTokenizer((String)codebaseAttr.get());
208-
Vector<String> vec = new Vector<>(10);
208+
ArrayList<String> list = new ArrayList<>(10);
209209
while (parser.hasMoreTokens()) {
210-
vec.addElement(parser.nextToken());
210+
list.add(parser.nextToken());
211211
}
212-
String[] answer = new String[vec.size()];
212+
String[] answer = new String[list.size()];
213213
for (int i = 0; i < answer.length; i++) {
214-
answer[i] = vec.elementAt(i);
214+
answer[i] = list.get(i);
215215
}
216216
return answer;
217217
}
@@ -409,11 +409,10 @@ private static Reference decodeReference(Attributes attrs,
409409
ClassLoader cl = helper.getURLClassLoader(codebases);
410410

411411
/*
412-
* Temporary Vector for decoded RefAddr addresses - used to ensure
412+
* Temporary array for decoded RefAddr addresses - used to ensure
413413
* unordered addresses are correctly re-ordered.
414414
*/
415-
Vector<RefAddr> refAddrList = new Vector<>();
416-
refAddrList.setSize(attr.size());
415+
RefAddr[] refAddrList = new RefAddr[attr.size()];
417416

418417
for (NamingEnumeration<?> vals = attr.getAll(); vals.hasMore(); ) {
419418

@@ -464,7 +463,7 @@ private static Reference decodeReference(Attributes attrs,
464463
// extract content
465464
if (start == val.length()) {
466465
// Empty content
467-
refAddrList.setElementAt(new StringRefAddr(type, null), posn);
466+
refAddrList[posn] = new StringRefAddr(type, null);
468467
} else if (val.charAt(start) == separator) {
469468
// Double separators indicate a non-StringRefAddr
470469
// Content is a Base64-encoded serialized RefAddr
@@ -480,17 +479,17 @@ private static Reference decodeReference(Attributes attrs,
480479
decoder.decode(val.substring(start).getBytes()),
481480
cl);
482481

483-
refAddrList.setElementAt(ra, posn);
482+
refAddrList[posn] = ra;
484483
} else {
485484
// Single separator indicates a StringRefAddr
486-
refAddrList.setElementAt(new StringRefAddr(type,
487-
val.substring(start)), posn);
485+
refAddrList[posn] = new StringRefAddr(type,
486+
val.substring(start));
488487
}
489488
}
490489

491490
// Copy to real reference
492-
for (int i = 0; i < refAddrList.size(); i++) {
493-
ref.add(refAddrList.elementAt(i));
491+
for (int i = 0; i < refAddrList.length; i++) {
492+
ref.add(refAddrList[i]);
494493
}
495494
}
496495

‎src/java.naming/share/classes/com/sun/jndi/ldap/sasl/LdapSasl.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,7 +27,7 @@
2727

2828
import java.io.*;
2929
import java.security.cert.X509Certificate;
30-
import java.util.Vector;
30+
import java.util.ArrayList;
3131
import java.util.Hashtable;
3232
import java.util.StringTokenizer;
3333

@@ -216,13 +216,13 @@ public static LdapResult saslBind(LdapClient clnt, Connection conn,
216216
*/
217217
private static String[] getSaslMechanismNames(String str) {
218218
StringTokenizer parser = new StringTokenizer(str);
219-
Vector<String> mechs = new Vector<>(10);
219+
ArrayList<String> mechs = new ArrayList<>(10);
220220
while (parser.hasMoreTokens()) {
221-
mechs.addElement(parser.nextToken());
221+
mechs.add(parser.nextToken());
222222
}
223223
String[] mechNames = new String[mechs.size()];
224224
for (int i = 0; i < mechs.size(); i++) {
225-
mechNames[i] = mechs.elementAt(i);
225+
mechNames[i] = mechs.get(i);
226226
}
227227
return mechNames;
228228
}

0 commit comments

Comments
 (0)
Please sign in to comment.