1 import java.util.ArrayList; 2 import java.util.Collections; 3 import java.util.HashMap; 4 import java.util.Hashtable; // Compliant 5 import java.util.List; 6 import java.util.Map; 7 import java.util.Stack; // Compliant 8 import java.util.Vector; // Compliant 9 10 public class SynchronizedClassUsageCheck { } 11 12 interface IA { 13 // Noncompliant@+2 {{Replace the synchronized class "Vector" by an unsynchronized one such as "ArrayList" or "LinkedList".}} 14 // Noncompliant@+1 {{Replace the synchronized class "Vector" by an unsynchronized one such as "ArrayList" or "LinkedList".}} 15 Vector f3(Vector a); 16 } 17 18 class A implements IA { 19 List a = new Vector(); // Noncompliant [[sc=12;ec=24]] {{Replace the synchronized class "Vector" by an unsynchronized one such as "ArrayList" or "LinkedList".}} 20 Vector a1 = new Vector(); // Noncompliant {{Replace the synchronized class "Vector" by an unsynchronized one such as "ArrayList" or "LinkedList".}} 21 Hashtable a2 = new Hashtable(); // Noncompliant {{Replace the synchronized class "Hashtable" by an unsynchronized one such as "HashMap".}} 22 Map a3 = new Hashtable(); // Noncompliant {{Replace the synchronized class "Hashtable" by an unsynchronized one such as "HashMap".}} 23 Hashtable a4 = foo(); // Noncompliant {{Replace the synchronized class "Hashtable" by an unsynchronized one such as "HashMap".}} 24 HashMap a5 = new HashMap(); // Compliant 25 ArrayList a6 = new ArrayList(); // Compliant 26 Vector<Integer> a7; // Noncompliant {{Replace the synchronized class "Vector" by an unsynchronized one such as "ArrayList" or "LinkedList".}} 27 StringBuffer a8 = new StringBuffer(); // Noncompliant {{Replace the synchronized class "StringBuffer" by an unsynchronized one such as "StringBuilder".}} 28 java.util.Stack a9 = new java.util.Stack(); // Noncompliant {{Replace the synchronized class "Stack" by an unsynchronized one such as "Deque".}} 29 List l = null; // Compliant 30 List<Object> listeners = getVector(); // Compliant 31 32 A(Vector v) { // Noncompliant {{Replace the synchronized class "Vector" by an unsynchronized one such as "ArrayList" or "LinkedList".}} 33 a = v; 34 } 35 36 private static Hashtable foo() { // Noncompliant 37 return null; 38 } 39 40 private void f() { 41 System.out.println(Vector.class); // Compliant 42 a.addAll(new java.util.Vector()); // Compliant 43 java.util.Vector<Integer> result = null; // Noncompliant 44 List result2 = new java.util.Vector<Integer>(); // Noncompliant 45 } 46 47 private Vector getVector() { // Noncompliant [[sc=11;ec=17]]{{Replace the synchronized class "Vector" by an unsynchronized one such as "ArrayList" or "LinkedList".}} 48 return new Vector(); 49 } 50 51 public Vector a10; // Noncompliant {{Replace the synchronized class "Vector" by an unsynchronized one such as "ArrayList" or "LinkedList".}} 52 53 public java.util.Stack f2() { // Noncompliant {{Replace the synchronized class "Stack" by an unsynchronized one such as "Deque".}} 54 return null; 55 } 56 57 public void f(Vector a) { // Noncompliant [[sc=17;ec=23]] {{Replace the synchronized class "Vector" by an unsynchronized one such as "ArrayList" or "LinkedList".}} 58 } 59 60 @Override 61 public Vector f3(Vector a) { // Compliant 62 Vector b; // Noncompliant {{Replace the synchronized class "Vector" by an unsynchronized one such as "ArrayList" or "LinkedList".}} 63 return null; 64 } 65 public void f(Integer i) { // Compliant 66 } 67 } 68 69 interface AInterface { 70 // Noncompliant@+1 71 Vector a(Vector a); // Noncompliant {{Replace the synchronized class "Vector" by an unsynchronized one such as "ArrayList" or "LinkedList".}} 72 } 73 74 enum AEnum implements AInterface { 75 A,B,C; 76 77 Vector a; // Noncompliant {{Replace the synchronized class "Vector" by an unsynchronized one such as "ArrayList" or "LinkedList".}} 78 79 Vector b() { // Noncompliant {{Replace the synchronized class "Vector" by an unsynchronized one such as "ArrayList" or "LinkedList".}} 80 return null; 81 } 82 83 @Override 84 public Vector a(Vector a) { // Compliant 85 return null; 86 } 87 } 88 89 class B { 90 class Stack {} 91 B() {} 92 void foo(Stack stack) { // Compliant 93 } 94 } 95 96 class MyVector<T> extends Vector<T> { // Noncompliant {{Replace the synchronized class "Vector" by an unsynchronized one such as "ArrayList" or "LinkedList".}} 97 } 98 99 class InferedTypeFromLambda { 100 void foo(Vector<Vector<String>> v) { // Noncompliant 101 Collections.sort(v, (s1, s2) -> -1); 102 Collections.sort(v, (Vector<String> s1, Vector<String> s2) -> -1); 103 Collections.sort(v, (Vector<String> s1, Vector<String> s2) -> { 104 Vector<String> x = s1; // Noncompliant 105 return -1; 106 }); 107 } 108 } 109 class InvokeStringBufferMethod { 110 public String toString() { 111 StringBuffer buf = new StringBuffer(); // Noncompliant 112 113 for (int i = 0; i < fComponents.length; i++) { 114 buf.append(fComponents[i]); 115 } 116 117 return buf.toString(); 118 } 119 }