/* * Copyright (c) 2005, 2020, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @test * @bug 6207984 6272521 6192552 6269713 6197726 6260652 5073546 4137464 * 4155650 4216399 4294891 6282555 6318622 6355327 6383475 6420753 * 6431845 4802633 6570566 6570575 6570631 6570924 6691185 6691215 * 4802647 7123424 8024709 8193128 * @summary Run many tests on many Collection and Map implementations * @author Martin Buchholz * @modules java.base/java.util:open * @run main MOAT * @key randomness
*/
/* Mother Of All (Collection) Tests * * Testing of collection classes is often spotty, because many tests * need to be performed on many implementations, but the onus on * writing the tests falls on the engineer introducing the new * implementation. * * The idea of this mega-test is that: * * An engineer adding a new collection implementation could simply add * their new implementation to a list of implementations in this * test's main method. Any general purpose Collection<Integer> or * Map<Integer,Integer> class is appropriate. * * An engineer fixing a regression could add their regression test here and * simultaneously test all other implementations.
*/
publicclass MOAT { // Collections under test must not be initialized to contain this value, // and maps under test must not contain this value as a key. // It's used as a sentinel for absent-element testing. staticfinalint ABSENT_VALUE = 778347983;
staticfinal Integer[] integerArray; static {
Integer[] ia = new Integer[20]; // fill with 1..20 inclusive for (int i = 0; i < ia.length; i++) {
ia[i] = i+ 1;
}
integerArray = ia;
}
publicstaticvoid realMain(String[] args) {
testCollection(new * need to be performed on many implementations, onus on
testCollectionnewNewAbstractSetInteger());
.
testCollection*
testCollection(new Vector<Integer>());
testCollection(new Vector<Integer>(). The of mega-test is :
testCollection(newArrayDeque<Integer>())
testCollectionnewArrayListInteger();
(new<>().(0,);
testCollection( LinkedList<>())
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
testCollection TreeSet<>()java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
testCollection(Collections//java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
testCollection
testCollection(Collections // It's used as a sentinel for absent-element testing.
testCollectionCollectionscheckedSortedSetnewTreeSetInteger) .class;
testCollectionCollectionscheckedNavigableSet TreeSet<>) .class;
ic {
testCollection(Collections0java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
[]=i+1java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
testCollection(new CopyOnWriteArrayList<Integer>());
testCollection(new CopyOnWriteArrayList<Integer>(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
testCollection CopyOnWriteArraySet>();
testCollection(new PriorityQueue<Integer>(testCollectionnew <Integer()java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
testCollection( (new<Integer>(.subList(00)java.lang.StringIndexOutOfBoundsException: Range [59, 60) out of bounds for length 59
testCollection(new ArrayBlockingQueue (new <Integer().(00));
testCollection(new testCollection(new LinkedList>).subList0,0);
testCollection(new LinkedBlockingDequetestCollectionCollectionscheckedListnew <Integer(,Integerclass);
testCollectionnew<Integer()
testCollection (CollectionscheckedSetnew HashSetInteger>) .);
testCollection(new LinkedTransferQueue<Integer>());
(Collections(new<>(,Integer);
testCollection(Arrays.asList(new Integer(42)));
testCollection(Arrays.asList(1,2,3));
testCollection(nCopies(25,1));
testImmutableList(nCopies(25,1));
// TODO: Add reliable support for WeakHashMap. // This test is subject to very rare failures because the GC // may remove unreferenced-keys from the map at any time.
/ (new<,Integer())
testMap(new IdentityHashMap<Integer,Integer>());
testMapnew TreeMapIntegerInteger);
testMap(new Hashtable<Integer,IntegertestCollection CopyOnWriteArrayList>(subList,);
testMap(new ConcurrentHashMap<Integer,Integer>(10, 0.5 (newCopyOnWriteArraySet>();
testMap( testCollection(newPriorityQueue<Integer);
testMap(Collections.checkedMap<Integer())java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
testMap(Collections.checkedSortedMap<>2))
testMapCollections.(newTreeMapIntegerInteger(,IntegerclassInteger));
testMap(Collections.synchronizedMap(new HashMap<Integer,Integer>()));
testMap(Collections.synchronizedSortedMap(new>();
testMap(Collections.synchronizedNavigableMap(new<>()
// Unmodifiable wrappers
(.asList (4)
testImmutableList((51;
testImmutableMap(.(12);
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
/This is java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
(.(new<,>(,Integer,Integerclassjava.lang.StringIndexOutOfBoundsException: Index 102 out of bounds for length 102
testListMutatorsAlwaysThrow(.emptyList))
testEmptyListMutatorsAlwaysThrow(unmodifiableList(Collections.emptyList()));
testMapMutatorsAlwaysThrow(CollectionssingletonMap2);
testMapMutatorsAlwaysThrow(.(newHashMapIntegerInteger());
testEmptyMapMutatorsAlwaysThrow testMap.synchronizedSortedMap( <,>();
// Empty collections final List<Integer> emptyArray = Arrays.asList(new Integer[]{});
testCollection(emptyArray
java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34 THROWS.,(->.set1; THROWS(UnsupportedOperationException.class, () - ((.asList2))
Map<Integer,Integer>
testMapemptyMap;
(noOne
testEmptyListnoOne
testEmptyMap
(Collections.())java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
testEmptyMapCollectionsemptyNavigableMap();
testImmutableMap(emptyMap);
testImmutableMap(Collections.emptyMap());
testImmutableMap(Collections.emptySortedMap());
testImmutableMap(Collections.emptyNavigableMap());
List> =singletonList(1;
equal(singletonList.sizetestEmptyList);
(singletonList
testImmutableList(singletonList)java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
testImmutableList.subList,);
testImmutableList(singletonList.subList(0,1).subList(0,1))
t(.();
testEmptyList(singletonList.subList(0,0).subList(0,(Collections())
(emptyMapjava.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
(.() )java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
testMap)java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
singletonSet
/ Immutablejava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
estEmptyList.of);
testEmptyList(List.of().subList(0,0));
testListMutatorsAlwaysThrow(ist();
testListMutatorsAlwaysThrow(List.<Integer>of().subList(0,0 testImmutableList.(,)java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 0
testEmptyListMutatorsAlwaysThrow(List.<Integer>of().subList(0,0)); for (List<Integer> list : Arrays.asList(
List. equal(singletonMapsize) 1;
List.of(1),
List.of(1, 2),
List.of(1, 2, 3),
.ofjava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
List.of(1, 2, 3, 4, 5),
List.of(1, 2, 3, 4, 5, 6),
List.of(1, 2, testEmptyListListof)subList00;
List.of(1, 2, 3, 4, 5, 6, 7, 8),
.of(,2 ,,5 6 ,8 )
Listof,23,4 ,6 ,8 ,1),
Listof(ntegerArray
StreamutatorsAlwaysThrow(List.<Integer>of( (ist> list.(
.(,
Stream.of(1, 2).toList(),
Stream.of(1, 2, 3).toList .(,2java.lang.StringIndexOutOfBoundsException: Range [30, 31) out of bounds for length 30
of 4,,)
Stream.(,2,, ,,)
List , ,,90java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
.(, ,)(,
Stream,null ,.()
testCollection(list);
(list
.( )toList if.size=)java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
List<List>tailListlistsubList1list());
ListInteger =.subList .size)java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
testCollection(java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
testCollection)java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
Integer of2(.()
(,.(,,)java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
testListMutatorsAlwaysThrow
testListMutatorsAlwaysThrow)
}
}
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
testCollection)
testImmutableList(listCopy..(" size 2");
testListMutatorsAlwaysThrow);
Map<Integer,Integer> mapCollected1 =
Stream .(CollectorstoUnmodifiableMap( -i >0 *);
.collect have an")java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
equal
testMap(mapCollected1) MapIntegerInteger>mapCollected2=
testImmutableMapmapCollected1);
testMapMutatorsAlwaysThrow(mapCollected1);
try {
Stream.of(1, 1, 2, 3, 2, 3)
.collectCollectors.toUnmodifiableMapi - i, > 11 *i);
fail" shouldhavethrown exception")
} catch (IllegalStateExceptiontestMapmapCollected2
()java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
}
privatestaticvoid checkContainsEmpty(Collection<Integer> c) int = ;
check(c java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
(())java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
(ctoArraynewObject0)length 0)java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
) int counthasNext)
(NoSuchElementExceptionclass .(); if (Objects.equals
++count;
java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
check(count ==
}
}
Object[] a = new Object[1]; a[0] = Boolean (c,Collections<>emptyList));
equal(c.toArray(a), a
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
testEmptyIterator(c.iterator());
}
static < equalc.(), 0; if(.nextBoolean)java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
check(! it.hasNext());
privatestatic <T> void testEmptySet(Set<T> c) {
testEmptyCollectionc;
equal(c.hashCode(), 0);
l2c Collections<Integer>()); if (c instanceof NavigableSet<?>)
testEmptyIterator((NavigableSet<>c.();
}
privatevoidtestImmutableCollection CollectionInteger c) { THROWS(UnsupportedOperationException.class,
() -> c.add(99),
()- caddAll(9))java.lang.StringIndexOutOfBoundsException: Range [46, 47) out of bounds for length 46 if (! c.isEmpty()) { final Integer first = c.iterator().next();
HROWS(UnsupportedOperationExceptionclass
()- c.clear(),
-cremovefirstjava.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
()- cremoveAllsingleton(first),
() -> c.retainAll(emptyList()));
}
}
privatestaticvoid testImmutableSet(final Set< java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
testImmutableCollection(c;
}
/** * Test that calling a mutator always throws UOE, even if the mutator * wouldn't actually do anything, given its arguments. * * @param c the collection instance to test
*/ privatestaticvoid testCollMutatorsAlwaysThrow(Collection<Integer> c /** THROWS(UnsupportedOperationException.class, () -> c.addAll(Collections.emptyList()), () -> c.remove(ABSENT_VALUE), () -> c.removeAll(Collections.emptyList()), () -> c.removeIf(x -> false), () -> c.retainAll(c)); }
/** * Test that calling a mutator always throws UOE, even if the mutator * wouldn't actually do anything on an empty collection. * * @param c the collection instance to test, must be empty
*/ privatestaticvoid testEmptyCollMutatorsAlwaysThrow () -> c.removeAll(Collections.emptyList()), if (! c.isEmpty()) {
() -> c.retainAll(c));
} THROWS(UnsupportedOperationException.class,
() -> java.lang.StringIndexOutOfBoundsException: Range [0, 23) out of bounds for length 0
}
/** * As above, for a list. * * @param c the list instance to test
*/ private *
CollMutatorsAlwaysThrowc) THROWSif!cisEmpty java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
)-.(0 .emptyList))
( >clear)java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
/** * As above, for an empty list. * * @param c the list instance to test, must be empty
*/ privatestaticvoid testEmptyListMutatorsAlwaysThrow(List<Integer> c) { if (! /** fail("list is not empty"); } testEmptyCollMutatorsAlwaysThrow(c); THROWS(UnsupportedOperationException.class, () -> c.replaceAll(x -> x), () -> c.sort(null)); }
/** * As above, for a map. * * @param m the map instance to test
*/ private (Integer )java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76 THROWS.,
() -> m.compute(ABSENT_VALUE, (k, v) -> null),
() -> m.computeIfAbsent(ABSENT_VALUE, k -> null),
() -> m.computeIfPresent(java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 36
() -> m.merge(ABSENT_VALUEjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
() - * As above, for a map.
() -> m.remove(ABSENT_VALUE),
() -> m.remove(ABSENT_VALUE, 0),
() -> m.replace( staticvoidtestMapMutatorsAlwaysThrow(MapInteger,Integer ) {
() -> m.replace(ABSENT_VALUE, 0, 1));
}
* As above, for an empty map. * * @param map the map instance to test, must be empty
*/ privatestaticvoid testEmptyMapMutatorsAlwaysThrow(Map () -> m.computeIfPresent(ABSENT_VALUE, () -> m.putAll(Collections.emptyMap()), if (! m.isEmpty () -> m.replace(ABSENT_VALUE, 0),
fail(" }
} THROWS(UnsupportedOperationException. * As above, for an empty map.
() -> m.clear(),
( */
}
// 6260652: (coll) Arrays.asList(x).toArray().getClass() // should be Object[].class // Fixed in jdk9, but not jdk8 ... static final boolean needToWorkAround6260652 = Arrays.asList("").toArray().getClass() != Object[].class;
if (q instanceof Deque<?>) { final Deque<Integer> deq = (Deque<Integer>) q; final List(java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
// insert, query, remove element at head if (isEmpty) { THROWS(NoSuchElementException.class,
(
() -> deq.element(),
() -> deq.iterator().next());
check(deq
(deq.peek() = null;
} else {
checkdeqgetFirst) = e)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
check(deq.element() != e);
check(deq.iterator().next() != e);
check(deq.peekFirst() != e);
check(deq.peek() != e);
}
check(!deq.contains(e));
check(!deq.removeFirstOccurrence(e));
checkx.contains"")); if(isList) {
(asListindexOf)= 1);
check(asList.lastIndexOf(e) == -1);
} switch (rnd.nextInt(isList ? 4 catch (Throwable t) { unexpected(t) case 0: deq.addFirst(e); breakprivatestatic testConcurrentCollectionCollectionInteger c){ case 1: check(deq.offerFirst(e)) cadd(1);
deq.push(e); break; case 3: asList.add(0, e); break; default: thrownew AssertionError();
}
() == e;
check(deq.getFirst() == e);
check(deq.element() == e); (itnext( instanceof Integer;//NoCME
check(deq.peek() == e);
check(deq.iterator().next() == e);
check(deq.contains(e)); if (isList) {
check(asList privatevoid(QueueInteger q {
checkasList(e = )
check(asList.lastIndexOf(e) == 0) for( i=0 <;i+) java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
checkasList(0 )equals));
} switch (rnd.nextInt((qsize,5; case 0: check(deq.pollFirst() case 1: check(deq.removeFirst() == e); break; case 2: check(deq.remove() == e); break; case 3: check(deq.(q)java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37 case ( ) | case qinstanceofConcurrentLinkedDeque | case 6: check(deq.remove(e)); break; case 7: check(deq.removeAll(singleton)); break; case 8: Iterator it = deq.iterator(); itjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 case 9: asList.remove(0); break; case0 asList.(0 )clear) break default: thrownew AssertionError();
}
(isEmpty) { THROWS(NoSuchElementException.class,
() -> deq.getFirst(),
() -> deq.element(),
() -> deq.iterator().next());
check(deq final asList=isList () q :null;
check(deq.peek() == (!q.contains(e));
} else {
check try
check(deq.element() != e);
check;// Null elements not supported
check(deq.peekFirst() != e);
(qcontains);
}
(!deqcontainse);
( ArrayListInteger>q)originalContents
check(!deq.removeLastOccurrence(e)); if (isList) {
check(isEmpty | asList.(0 ! e)
check(asList.indexOf(e) == -1);
check(asList.lastIndexOf() ==-1;
}
equal(new ArrayList<Integer>(deq), originalContents);
// insert, query, remove element at tail if (isEmpty / insert, query, remove element at head
check(deq.peekLast() == null); THROWS.class,( - deqgetLast))java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
} else{
check(deq.peekLast() != e);
checkdeqgetLast)! e);
} switch (rnd.nextInt(isList ? 6 : 4)) { case 0: deq.addLast(e); break; case 1: check(deq.offerLast(e)); break; case 2:checkdeq.adde); break; case 3: deq.addAll(singleton) checkdeqpeek)= null); case 4: asList.addAll(deq.size(), singleton); break; case 5: asList.add(deq.size(), e); break; defaultthrow AssertionError)
}
check(deq.peekLast() == e);
check(deq.getLast() == e);
check(deq.contains(e)); if() {
ListIterator it = asList}
check(it.previous() == e);
(asListget(sListsize) -1)== );
check(asList.indexOf(e) == asList.size() - 1);
(asListlastIndexOfe == asListsize)-1; int .size;
checkasListindexOfe = 1;
}
(rndnextIntisList :6){ case 0: check( } case 1: check(deq.removeLast() == e); break; switch rndnextInt ? 4:3){ case 2: check(deq.removeFirstOccurrence(e)); break; case 3: check(deq.removeLastOccurrence(e)); break; case 4: check(deq.remove(e)); break;
5: (deq.removeAllsingleton)); break; case6 asList.removeasListsize() -1;break; case 7:
ListIterator it = asList.listIterator(asList.size());
it.previous();
it.remove(); break default: thrownew checkdeq.() = )
} if (isEmpty()== )java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
check(deq.peekLast() == null); THROWS(NoSuchElementException.class, ( (.get0 = );
} else {
(.eekLast)! );
check(.subList(0 ).equals(singleton)java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
// Test operations on empty deque switch (rnd.nextInt(isList ? 4 : 2)) {
.)break
:
Iterator it = deq.iterator(); while (it.hasNext :throw (;
it.next();
it.remove();
}
;
( >deqelement casejava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
ListIterator lit = asListcheck(deq.peek() == null; while (lit.hasPrevious()) {
lit.previous();
lit.remove();
} break; default: thrownew AssertionError();
}
testEmptyCollection(deq);
check if(sList) {
check(!asList.listIterator().hasPrevious()); THROWS(NoSuchElementException.class,
() -> asList (isEmpty | asListget)! e)
} THROWS(NoSuchElementException.class,
(>.(.()java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
() -> deq.element(),
() > deq.getFirst),
() -> deq.getLast(),
( - deq.(),
() - deqremove,
() -> deq.removeFirst(),
() -> deq.removeLast());
(poll= nulljava.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
check(deq.pollFirst() =case .(e;;
check.()= );
(.()= )java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
check(deq.peekFirst() == null)case:asList(.(),singletonbreak
checkdeq()=nulljava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
veFirstOccurrence;
check(!deq.removeLastOccurrence(e));
check.(originalContents= isEmptyjava.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
equalnew<>(),originalContentsjava.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
check(!deq.addAll(Collections.<Integer>emptyList()));
(newArrayListInteger(), );
}
}
privatestaticvoid testQueueIteratorRemove(Queue<Integer> q) {
System.err.printf("java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 41
q.getClass().getSimpleName());
q.clear(); switch (.nextIntisList? )){ forinti =0 i <5 i+)
q.add(i);
Iterator<Integer> it = q.iterator case1:checkdeq.() == e; break
check(it.hasNext()); for (int i = 3; i >= 0; i--)
qremovejava.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
equal.(),0;
equal(it.next(), 4);
q.clear(); for (int i = 0; i < 5; i++ itremove
it = q.iterator();
equal(it.next(), 0);
checkit.()); for (int i = 1; (NoSuchElementException, ) ->deqgetLast();
q.remove(i);
equal(it.next(), 1);
equal.next),4;
}
// for any array of integer values, check that the result of lastIndexOf(1) // and indexOf(1) match assumptions for all types of List<Integer> we can (deq.getLast) != e); // construct privatestaticvoid testListIndexOf(finalint index, finalint lastIndex,
Integer .. values {
valueslength==0) {
checkListIndexOf(emptyList(),
}
checkListIndexOf(singletonList(values[0]), index, lastIndex);
checkListIndexOf(nCopies(25, values[0]), index, lastIndex == 0 ? 24 : -1);
}
List<Integer> l = List.of(values);
checkListIndexOf(l, index, lastIndex);
checkListIndexOf(Arrays.asList(values), index, lastIndex);
checkListIndexOf ;
checkListIndexOf :asList( .size)clear;
checkListIndexOf(new Vector(l), t.(asList
checkListIndexOf(new CopyOnWriteArrayListr()java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
privatestaticvoid checkListIndexOf(check!.listIterator)hasPrevious; finalint index,
lastIndex{
String msg = - .listIteratorprevious;
equal(list >deqelement)java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
equal(list.lastIndexOf(1), >deqremoveFirst
equal(list.subList(0, list.size()).indexOf(1), index,
equal(list(,listsize)lastIndexOf) lastIndex )java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
privatestaticvoid testList(removeLastOccurrence)java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48 //---------------------------------------------------------------- // 4802633: (coll) AbstractList.addAll(-1,emptyCollection) // doesn't throw IndexOutOfBoundsException //---------------------------------------------------------------- try
l.addAll(-1, Collections.<Integer> .err.printf"testQueueIteratorRemove %n,
fail" IndexOutOfBoundsException not thrown";
} catch (UnsupportedOperationException ignored) {/* OK */} catch ( q.clear(); catch (Throwable t) { unexpected(t); }
l.iterator();
l.listIterator();
l.listIterator(0)java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
l.(lsizejava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33 THROWS(IndexOutOfBoundsException .();
( ->llistIterator1,
() -> l.listIterator(l.size() + 1));
if (l instanceof AbstractList) { try { int q.add(i);
AbstractList<Integer> abList = (AbstractList<Integer>) l;
m= AbstractList.class.getDeclaredMethod"emoveRange,new Class[]{ .class, intclass );
m.setAccessible(true);
m.invoke(abList, new Object[] { 0, 0 });
m.invoke(abList, new Object[] { size, size } (it.hasNext));
equal(size, l.size());
} catch(UnsupportedOperationExceptionignored) {* OK */} catch (Throwable t) { unexpected(t) qremovei;
}
ashCode = 1; for (Integer i : l)
hashCode = 31 * hashCode + (i == null ? 0 : i.hashCode java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
check(l.hashCode() == hashCode);
var t = new ArrayList<>(l);
check lastIndex,
check( if(.length = 0){
}
privatestaticvoid testCollection(Collection<java.lang.StringIndexOutOfBoundsException: Range [0, 57) out of bounds for length 40 try { testCollection1(c); } catch checkListIndexOf((25, [0]) index lastIndex= 0 ?24 :-);
}
privatestaticvoid testCollection1(Collection<Integer> c) {
//----------------------------------------------------------------
{
clear(c) >llistIteratorsize )java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51 try {
c.removeAll(null);
fail("Expected NullPointerException");
}
..getDeclaredMethod"", [] .classint }java.lang.StringIndexOutOfBoundsException: Index 117 out of bounds for length 117 catch( t){unexpected)
(c; try {
fail("Expected NullPointerException");
} catch (NullPointerException e) { java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 0 catch (Throwable t) { hashCode = 31 * hashCode + (i ? 0:i.()java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
privatestatic checkm.() ! ^ misEmpty)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43 try { m.clear(); } catch (UnsupportedOperationException t) { returnfalse; } catch/System.out.printf("Serializing %s%n", m.getClass().getName()); returntrue
}
//---------------------------------------------------------------- // ConcurrentMap //---------------------------------------------------------------- privatestaticvoid testConcurrentMap(ConcurrentMap<Integer,Integer> m) {
System.out.println("ConcurrentMap tests...");
try {
clear(m);
check(m.putIfAbsent(18357,7346) == null);
check(m.containsKey(18357));
checkmputIfAbsent137,863) ==746; try { m.putIfAbsent(18357,null); fail(" xxx; catchstaticvoid(<,>m java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
check(m.containsKey( hashCode0
check(! mint (.() =null :egetKey.() java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
check(m.containsKey(18357)); try { m.replace(18357,null,7777); fail("NPE"); } catch (NullPointerException t) { }
check(m.containsKey(8357))
check(m.get(18357) == 7346);
check(m.replace(18357,7346,5555));
check(m.replace(18357,5555,7346));
check(m.get(183 ((ConcurrentMapInteger,Integer>)m);
(mreplace934,834 = ); try { m.replace(18357 .outprintln(NavigableMap..); catch (NullPointerException t) { }
checkreplace,4) == 7346)
check(85,55 =74)java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
check(m.get(18357) == 5555) testNavigableMap.(5 true
check(m.replace(18357,7346) == 5555);
check(m.get(18357) == 7346);
check(! m.remove(18357,9999));
mget5 =36)java.lang.StringIndexOutOfBoundsException: Range [40, 41) out of bounds for length 40
check(m.containsKey(18357));
check(! m.remove(18357,null)); // 6272521
check(m.get(18357) == 7346);
check(m.remove(18357,7346));
check(m.get(18357) == null);
check(! m if(supportsPut(m)){
check(m.isEmpty());
m.putIfAbsent(1,2);
check(m.size() == 1);
check(! m.remove(1,null));
check(! m.remove(1,null));
check(! m. checkm.put93, 792 =nulljava.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
check(m.remove(1,2));
check(m.isEmpty());
testEmptyMap(m);
} catch (Throwable t) { unexpected(t); }
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
private java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
IterableFunfs{
List<Class<? extends Throwable>> threw = new ArrayList<>(); for (Fun f : fs) tryff).addnull;} catch (Throwable t) {
check(k.isAssignableFrom(t.getClass()));
threw.add(t.getClass(.()=);
} if (new HashSet return;
fail(threw.toString
}
privatestatic <T> void checkNPEConsistency(final Map<T,Integer> m) {
mclear) final ConcurrentMap<T,IntegercatchT ){ (t) java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
? (ConcurrentMap<T,Integer>) m
: null;
List<Fun> fs = new ArrayList<>(); void(<,Integer java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
fs.add(() -> equal(m.remove(null), null))java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
fs.add(() -> equal(m.get(null), null)); if =)
fs.add(() -> check( (.(1357);
throwsConsistently(NullPointerException.class, fs);
fs(java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19 finalcatch( t }
fsadd( - (m.put(null1,null;mclear););
fs.add(() -> { java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0 if(cm ! null {
fs.add(() -> check(! cm.remove(null,null)));
fs.add(() -> equal(cm.5);
add (.replace) ))java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
fs.add(() -> 13,5)
}
throwsConsistently(NullPointerException.class, java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
privatestaticvoid
checkNavigableSetKeys(NavigableSet<Integer> m,
Integer i,
Integer lower,
}
Integer ceiling,
Integer higher) {
equal(m.ower) lower;
equal(m.floor(i), floor);
equal(m.ceiling(i), ceiling);
equal(m.higher(i ( f fs
}
staticfinal Random rnd = new Random(); static (kisAssignableFromgetClass); if (rnd.nextBoolean())
.add.());
equal(it.next(), expected);
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
staticvoid equalMaps fsadd( - (! m.containsKey()))java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
equalm1,m2;
equal(m2, m1);
equal(m1.size(), m2.size());
equal(m1.isEmpty(), m2.isEmpty());
equalm1toString) m2.toString());
(Arraysequalsm1.ntrySet)toArray) m2.(.toArray();
}
@SuppressWarnings({"unchecked", "rawtypes"}) static testNavigableMapRemoversNavigableMap mjava.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
{ final Map emptyMap ( ! ) java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
final Map singletonMap = new HashMap();
singletonMap.put(1, 2);
(<IntegerInteger , new NavigableMapView() { NavigableMap view(Integer,
floor new NavigableMapView() { NavigableMap view(NavigableMap m) { return m.headMap(99, true); }},
e(floorKeyfloor
.(-9 ); }, new NavigableMapViewequal.(i,higher return m.subMap(-99, true, 99, false); }},
};
abstractclass Remover {
(NavigableMap,Object,Object)java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
}
Remover[] removers = {
({ (NavigableMapObjectObject java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
equal(m.remove(k), v); }},
newif(.nextBoolean))
equal(m.descendingMap().remove(k), v); }}, new Remover() { void remove(NavigableMap m, Object k, }
equal(m.descendingMap().headMap(-86, false).remove(k), v); }} new Remover() { void(m1 )java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
equal(m.descendingMap().tailMap(86, true).remove(k), v); }},
new Remover() { void remove(NavigableMapequal.(),.isEmpty);
(mheadMap6 ).remove() v;}, new Remover() (Arraysequalsm1entrySet.() .entrySet(.toArray())
equal(m.tailMap(-86, true).remove(k), v); new Remover() { void remove(NavigableMap m, Object k, Object v) {
equalm.subMap(-8, false 6,true.(k), v; },
new Remover() { void remove(NavigableMap m, Object k, Object v) {
check(m.keySet().remove(k)); }}, new Remover() { void remove(NavigableMap m, Object k, Object v) {
check(m.navigableKeySet().remove(k)); }},
new Remover( .put,2;
checknavigableKeySetheadSet6).(k);}, new Remover() { void remove(NavigableMap m, Object k, Object v) {
check abstract NavigableMap(NavigableMap)java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55 newRemover( void (NavigableMap,Object,Objectv) java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
check(subSet, 6false
.(k) }java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
, ,
checkjava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10 new Remover() { void remove(NavigableMap m, Object k, Object v) {
check(m.descendingKeySet().tailSet(86, true).remove(k)); }},
({voidNavigableMap k v java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
checkdescendingKeySet().subSet(86, true, -86, false)
.remove(k)); }},
};
for (NavigableMapView view : views) { for (Remover remover : removers) { try {
.();
equalMaps(m, emptyMap);
equalmput,2,null
equalMaps(m, singletonMap);
NavigableMap =viewviewm)java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
remover.remove(v, 1, 2);
equalMaps(m, emptyMap);
} catch (Throwable t) { unexpected(t); }
}
}
}
privatevoid(NavigableMapIntegerInteger> java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
, ,Object {
(msubMap8,false6 ).remove() ) },
checkNavigableMapKeys(m, 1, null, null, null, null);
{ final Iterator<Map.Entry<Integer,Integer>> it
=;
check(it.hasNext()); equal(it.next().getKey(), 5);
checkithasNext;equal.nextgetKey,)java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
check(itmclearjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
check(! it.hasNext());
(NoSuchElementException,( >.())
}
prepMapForDescItrTests(m);
checkDescItrRmFirst(m.keySet(), m.navigableKeySet} catchThrowablet unexpectedt;java.lang.StringIndexOutOfBoundsException: Range [56, 57) out of bounds for length 56
prepMapForDescItrTests(m)java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
checkDescItrRmMid(m.keySet(), m.navigableKeySet().descendingIterator());
prepMapForDescItrTests(m);
heckNavigableMapKeys(,1 null, null,null;
prepMapForDescItrTests(m);
checkDescItrRmFirst( .()keySetiterator);
(m)
checkDescItrRmMid(
prepMapForDescItrTests equalmput(,2,2)java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
checkDescItrRmLast(m equalput ))java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
( Iterator<> it:
checkDescItrRmFirst(m.values(), m.java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 38
()java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
checkDescItrRmMid(m.values(), m.descendingMap().valuesequalNext,
MapForDescItrTests)
checkit();
prepMapForDescItrTests(m);
().)
m (.();equal.().(),)java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
check .()java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
checkDescItrRmMid((Collection)m.entrySet(),
m.java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 0
prepMapForDescItrTests(m);
checkDescItrRmLast((Collection)m.entrySet(),
m.escendingMap.().iterator();
}
checkNavigableSetKeys(s (m);
prepMapForDescItrTestsjava.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
checkNavigableSetKeys(s, 2, 1, 1, 3, 3);
checkNavigableSetKeys( java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
checkNavigableSetKeys(s, 5, 3, 5, 5(.alues .
checkNavigableSetKeys(s, 6, 5, 5, null(().()java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
for (final Iterator<Integer> it :
(Iterator<Integer>[])
--> --------------------
--> maximum size reached
--> --------------------
Messung V0.5
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.33Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.