ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/Vector.java
(Generate patch)

Comparing jsr166/src/main/java/util/Vector.java (file contents):
Revision 1.43 by jsr166, Wed Dec 21 05:15:08 2016 UTC vs.
Revision 1.49 by jsr166, Sat Apr 28 16:25:34 2018 UTC

# Line 1 | Line 1
1   /*
2 < * Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
2 > * Copyright (c) 1994, 2018, Oracle and/or its affiliates. All rights reserved.
3   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4   *
5   * This code is free software; you can redistribute it and/or modify it
# Line 25 | Line 25
25  
26   package java.util;
27  
28 + import java.io.IOException;
29 + import java.io.ObjectInputStream;
30 + import java.io.StreamCorruptedException;
31   import java.util.function.Consumer;
32   import java.util.function.Predicate;
33   import java.util.function.UnaryOperator;
# Line 70 | Line 73 | import java.util.function.UnaryOperator;
73   *
74   * <p>As of the Java 2 platform v1.2, this class was retrofitted to
75   * implement the {@link List} interface, making it a member of the
76 < * <a href="{@docRoot}/../technotes/guides/collections/index.html">
76 > * <a href="{@docRoot}/java/util/package-summary.html#CollectionsFramework">
77   * Java Collections Framework</a>.  Unlike the new collection
78   * implementations, {@code Vector} is synchronized.  If a thread-safe
79   * implementation is not needed, it is recommended to use {@link
# Line 307 | Line 310 | public class Vector<E>
310          if (newSize > elementData.length)
311              grow(newSize);
312          final Object[] es = elementData;
313 <        for (int to = elementCount, i = elementCount = newSize; i < to; i++)
313 >        for (int to = elementCount, i = newSize; i < to; i++)
314              es[i] = null;
315 +        elementCount = newSize;
316      }
317  
318      /**
# Line 1026 | Line 1030 | public class Vector<E>
1030                      setBit(deathRow, i - beg);
1031              if (modCount != expectedModCount)
1032                  throw new ConcurrentModificationException();
1029            expectedModCount++;
1033              modCount++;
1034              int w = beg;
1035              for (i = beg; i < end; i++)
# Line 1177 | Line 1180 | public class Vector<E>
1180      }
1181  
1182      /**
1183 +     * Loads a {@code Vector} instance from a stream
1184 +     * (that is, deserializes it).
1185 +     * This method performs checks to ensure the consistency
1186 +     * of the fields.
1187 +     *
1188 +     * @param in the stream
1189 +     * @throws java.io.IOException if an I/O error occurs
1190 +     * @throws ClassNotFoundException if the stream contains data
1191 +     *         of a non-existing class
1192 +     */
1193 +    private void readObject(ObjectInputStream in)
1194 +            throws IOException, ClassNotFoundException {
1195 +        ObjectInputStream.GetField gfields = in.readFields();
1196 +        int count = gfields.get("elementCount", 0);
1197 +        Object[] data = (Object[])gfields.get("elementData", null);
1198 +        if (count < 0 || data == null || count > data.length) {
1199 +            throw new StreamCorruptedException("Inconsistent vector internals");
1200 +        }
1201 +        elementCount = count;
1202 +        elementData = data.clone();
1203 +    }
1204 +
1205 +    /**
1206       * Saves the state of the {@code Vector} instance to a stream
1207       * (that is, serializes it).
1208       * This method performs synchronization to ensure the consistency
# Line 1454 | Line 1480 | public class Vector<E>
1480  
1481          @SuppressWarnings("unchecked")
1482          public boolean tryAdvance(Consumer<? super E> action) {
1483 +            Objects.requireNonNull(action);
1484              int i;
1458            if (action == null)
1459                throw new NullPointerException();
1485              if (getFence() > (i = index)) {
1486                  index = i + 1;
1487                  action.accept((E)array[i]);
# Line 1469 | Line 1494 | public class Vector<E>
1494  
1495          @SuppressWarnings("unchecked")
1496          public void forEachRemaining(Consumer<? super E> action) {
1497 <            if (action == null)
1473 <                throw new NullPointerException();
1497 >            Objects.requireNonNull(action);
1498              final int hi = getFence();
1499              final Object[] a = array;
1500              int i;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines