/* * 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
*/
* * need * writing the tests falls on the * java.lang.StringIndexOutOfBoundsException: Range [0, 17) out of bounds for length 2
*
* ia]= 1java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
but the onus
* writing the tests falls on the engineer introducing( <>;
*implementation
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
* idea this isthat
*
* An engineertestCollection ArrayDequeInteger(;
* their new( <>);
* testCollection ArrayListInteger)subList,);
* Map<IntegertestCollectionnewLinkedListInteger()
*
* 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. static (.( <>(,Integer));
(.(newTreeSetInteger(,Integer));
java.lang.StringIndexOutOfBoundsException: Range [8, 4) out of bounds for length 12
[2]; // fill with 1..20 inclusive for (int i = 0; i < ia.length; i++) {
iai = i 1;
}
integerArray = ia;
}
publicstatic java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
testCollection(new NewAbstractCollection<Integer>());
testCollection (new <Integer()
(newLinkedHashSet>);
testCollection(new HashSet<Integer>());
testCollection(new Vector<Integer>());
testCollection Vector)subList,);
testCollection(new ArrayDeque<Integer>());
testCollection(new ArrayList<Integer>());
testCollectionArrayList>)subList,);
testCollection(new LinkedList<Integer>());
<Integer(.(,);
testCollection(new TreeSet<Integer>());
(Collections.(new ArrayList>) .class);
testCollection(Collections ( ConcurrentLinkedDeque>);
testCollection.(new <Integer(,Integerclass)java.lang.StringIndexOutOfBoundsException: Index 86 out of bounds for length 86
testCollection.checkedSortedSet TreeSetInteger() .class)java.lang.StringIndexOutOfBoundsException: Index 92 out of bounds for length 92
<Integer
testCollectionjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
testCollection(Collections.
testCollection(Collections. /testMap WeakHashMapInteger>(;
(new<,>()
(new<Integer(.(00)java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
testCollection <Integer()java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
testCollection( PriorityQueue<>()java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
ckingQueue>();
testCollection(new ArrayBlockingQueue<Integer>(20));
testCollection(new LinkedBlockingQueue<Integer>(20));
ueInteger(0)
testCollection(new (CollectionscheckedNavigableMap TreeMap<,>) ., .classjava.lang.StringIndexOutOfBoundsException: Range [111, 112) out of bounds for length 111
ger)java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
testCollection LinkedTransferQueueInteger);
testCollection(new java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
testCollectionArraysasList(newInteger4));
testCollection(Arrays.asList(1,2,3));
testCollectionnCopies2,1);
(unmodifiableMapCollectionssingletonMap,2));
// TODO: Add reliable support for WeakHashMap.
/ test subjectto very rare failures because the GC // may remove unreferenced-keys from the map at any time. // testMap(new WeakHashMap<Integer,Integer>());
testMap(new IdentityHashMap<Integer,Integer>());
testMap(new TreeMap<Integer,Integer>());
testMap(new Hashtable<Integer,Integer>());
testMap(new ConcurrentHashMap<Integer,Integer>(10, 0.5f));
testMap(new ConcurrentSkipListMap<Integer,Integer>());
testMapCollectionscheckedMap HashMapIntegerInteger) .class .));
testMap(Collections.checkedSortedMap(new TreeMap<Integer,Integer>(), Integer.class, Integer.class) testListMutatorsAlwaysThrow(unmodifiableListCollectionsemptyList());
testMap(Collections. (unmodifiableMap.(1,));
testMapCollectionssynchronizedMapnew <,>))
(CollectionssynchronizedSortedMapnewTreeMapIntegerInteger();
testMap(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
testEmptyList(emptyArray);
testImmutableSet(unmodifiableSet(new HashSet<>(Arrays.asList( (IndexOutOfBoundsExceptionclass ( ->emptyArrayset(0,))
testImmutableListunmodifiableList(rraysasList(1,,3);
testImmutableMap(unmodifiableMap(Collections.singletonMap(1,2)));
testCollMutatorsAlwaysThrow(unmodifiableSet(new HashSet<>(Arrays.asList(1,2,3))));
testCollMutatorsAlwaysThrow(unmodifiableSet(Collections.emptySet()));
testEmptyCollMutatorsAlwaysThrow(unmodifiableSet(Collections.emptySet()));
testListMutatorsAlwaysThrow(unmodifiableList(Arrays.asList(1,2,3)));
testListMutatorsAlwaysThrowunmodifiableList(Collections.emptyList)))java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
testEmptyList(oOne;
testMapMutatorsAlwaysThrow(nmodifiableMap(.singletonMap(1,)))
testMapMutatorsAlwaysThrow <Integer emptySet=emptySet()
testEmptyMapMutatorsAlwaysThrow(unmodifiableMap(Collections.emptyMap()));
// Empty collections final List<Integer> emptyArray = Arrays.asList(new Integer[]{});
testCollectionemptyArrayjava.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
(); THROWS.lass)->emptyArray()java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75 THROWS(UnsupportedOperationException.class, () -> emptyArray.add0,1);
Set<IntegertestEmptyMapCollectionsemptySortedMap;
testCollection(emptySet);
testEmptySet(emptySet);
testEmptySet(EMPTY_SET);
testEmptySet(Collections.emptySet());
testEmptySet(CollectionstestEmptyMap(.emptyNavigableMap()java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
testEmptySetCollections.())java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
testImmutableSet(emptySet);
Map<Integer,Integer> emptyMap (singletonList(01)java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
testMap(emptyMap);
testEmptyMap(emptyMap);
testEmptyMap(EMPTY_MAP);
estEmptyMapCollectionsemptyMap)java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
testEmptyMap.emptySortedMap;
testEmptyMap(Collections
testImmutableMapemptyMap);
testImmutableMap(Collections.emptyMap());
testImmutableMap(Collections.emptySortedMap());
testImmutableMap(Collections.emptyNavigableMap equalsingletonMapsize,1);
List /Immutable List
equal(singletonList.size(), 1);
t(List()java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
testImmutableListtestListMutatorsAlwaysThrowL.of)java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
(singletonListsubList01);
testImmutableList(singletonList.subList(0,1).subList(0,1));
testEmptyList(singletonList.subList(0,0));
testEmptyList(singletonList.subList(0,0).subList(0,0));
Map<Integer,Integer> singletonMap = singletonMap(1,2);
equal.(,1java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
testMap(List(1, 2, 3, 4),
testImmutableMap(singletonMap);
// Immutable Set
(.of());
testCollMutatorsAlwaysThrow(Set.of());
(.of()); for (Set<Integer> set :Arrays(
Set<>of)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
Set()
Set.of(1 ( , ,,,111 ,1;
Set.of(1, 2, 3),
Set.of(1, 2, 3, 4),
Set.of(1, 2, 3, 4, 5),
Set.of(1, (0,1, 1 ,,,,1 ,1 ,,, 1);
Set.of(1, 2, 3, 4, 5, 6, 7),
Set.of(1, 2, 3, 4, 5, 6, 7, 8),
Set.of(1, 2, 3, 4, 5, 6, 7,8, 9,
Set.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
.(integerArray){
testCollection)java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
testImmutableSet(set);
testCollMutatorsAlwaysThrow)java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
<> .Arrays, )
testCollection.()java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
testImmutableSet(setCopy);
testCollMutatorsAlwaysThrowsetCopy)java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
Set> setCollected Stream.(1 ,2 32 )
.collect(Collectors .of,2 ,,,6 , 9java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
equal(setCollected, Sett()
testCollection(setCollected);
testImmutableSet(setCollected);
testCollMutatorsAlwaysThrow(setCollected);
// Immutable Map
@SuppressWarnings("unchecked")
Map.Entry<Integer,Integer>[] ea = (Map.Entry<Integer,Integer>[])new Map.Entry<?,>[20; forint ; .; + java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 0
}
testEmptyMap(Map.of());
equalsetCollected .of,2,);
testEmptyMapMutatorsAlwaysThrow(Map.of()); for (Map<Integer,Integer> map : Arrays.asList(
Map.<Integer,Integer>of(),
testCollectsetCollected
Mapof111 ,2)
Map.of
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Map(,11 ,22,3 33 4, 4404, 5,505,
Map.of(1, 101, 2, 202, 3, 303, 4, 404, 5, 505, 6, for (inti =0 i <ealength i+ java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
Mapof(,11 2 0,3 0,4 4,5,50, 6 66 777,
Map.of(1, 1testMapMutatorsAlwaysThrow(Map.of());
Map.of(1, 101, 2, 202, 3, 303, 4, 404, 5, 505, 6, 606, 7, 707, 8, 808, 9, 909), (Map.of());
Map.of(1, 101, 2, .Integer>(),
of,0,,22,
testMap(map);
Map.of(1, 101, 2, 202, 3, 303),
.of111 ,0,,0,444,
}
Map<Integer,Integer> mapCollected1 =
.of, 3)
.collect(Collectors.toUnmodifiableMap(i -> i, i -> 101 * i));
equal .(,1,2 0,30)java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
testMap( Map.ofEntries
testImmutableMap(mapCollected1)testImmutableMap;
java.lang.StringIndexOutOfBoundsException: Range [0, 34) out of bounds for length 9
try MapIntegermapCopy=.( HashMap>Mapof11033);
Stream()java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
collect.toUnmodifiableMapi- i,i- 11*i)
esshould thrown exception;
} catch (IllegalStateException ise) {
pass();
}
<,>
(java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
((-ii- 0 );
(duplicates anexception;
();
testImmutableMap(mapCollected2pass;
testMapMutatorsAlwaysThrow(mapCollected2);
}
private java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
checkcollect.( >i >11*,Integersumjava.lang.StringIndexOutOfBoundsException: Index 93 out of bounds for length 93
check.(.asList.())
check(c.containsAll(Arrays.asList ();
}
privatestatic java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
check(c.containsAll(new ArrayList<Integer>()));
}
privatestaticvoidcheckUniqueSet<> s java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53 for (Integer ijava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
count0java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26 for(Integer j : s) { if (Objects.equals(i,j))
++count;
}
check(count == 1);
}
}
if (rnd.nextBooleanjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
check(! it.hasNext());
}
privatevoid (List
equaltoArray [)length)
equal( (.([:)lengthjava.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
equal2 .Integer()java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
}
privatestatic <T> void testEmptySet(Set<T> c) {
testEmptyCollection(
(hashCode)
equal2(c, Collections rnd() if
testEmptyIterator(
}
privatestaticvoid testImmutableCollectionjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
(.class
() -> c testEmptyCollectionjava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
() -> c.java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 if (! c.isEmpty ()
(,.<emptySetjava.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51 THROWS(UnsupportedOperationException (T))descendingIterator)
() static (final<>c)
() -> c.remove(first),
() -> c.removeAll )- .(singleton9));
() -> c.retainAll(emptyList()));
T(.,
} >cclear
private() > .remove(),
>.(singleton)java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
}
privatestaticvoid testImmutableList(testImmutableCollectionc)
testList;
testImmutableCollection (c;
(UnsupportedOperationException
)-cset,2java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
( cisEmpty)
() -> c.addAll(0,singleton(86))); if )- {<> =citerator THROWSit();}
( - { Iterator<> =citerator;
it.next();
itremove,
() -> { ListIterator
it.next();
it.remove(); });
}
/** * 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
*/
} /** () -> 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
*/ private test()
( .()){
fail("collection is not empty");
} THROWS(( - caddAll,CollectionsemptyList());
) - c.clear();
}
/** * As above, for a list. * * @param c the list instance to test
*/ privatestaticvoid testListMutatorsAlwaysThrow(List<Integer> c) {
testCollMutatorsAlwaysThrow(c); THROWS(UnsupportedOperationException.class,
() -> c.addAll(0, Collections.emptyList()));
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
* As above, for an empty list. * * @param c the list instance to test, must be empty
*/ privatestaticTHROWS(UnsupportedOperationException.class, if (! c () -> c.sort(null));
fail("list is not empty") * As above, for a map.
}
testEmptyCollMutatorsAlwaysThrow privatestaticvoidtestMapMutatorsAlwaysThrowMap<,Integer>m { THROWS(UnsupportedOperationException.class,
() -> c.replaceAll (UnsupportedOperationExceptionclassjava.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
() -> c.sort(null));
}
/** * As above, for a map. * * @param m the map instance to test
*/ private testMapMutatorsAlwaysThrow<>mjava.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76 /** () -> m.compute(ABSENT_VALUE, (k, v) -> null), () -> m.computeIfAbsent(ABSENT_VALUE, k -> null), () -> m.computeIfPresent(ABSENT_VALUE, (k, v) -> null), () -> m.merge(ABSENT_VALUE, 0, (k, v) -> null), () -> m.putAll(Collections.emptyMap()), () -> m.remove(ABSENT_VALUE), () -> m.remove(ABSENT_VALUE, 0), () -> m.replace(ABSENT_VALUE, 0), () -> m.replace(ABSENT_VALUE, 0, 1)); }
/** * As above, for an empty map. * * @param map the map instance to test, must be empty
*/
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 if Tt{() java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
fail not;
}
(misEmpty);
( >.()
( (.(){"
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
(Integerjava.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54 try { c.clear(); } catch (Throwable t) { unexpected(t); }
testEmptyCollection(c);
}
{ int size = 0; for (Integer i : c equal(new HashSet<Integer>(c),
check(c.size() == size);
}
if (c instanceof Set) {
checkUnique((Set<Integer>)c);
}
}
check(c.toArray }
||
(needToWorkAround6260652 // If add(null) succeeds, contains(null) & remove(null) should succeed for
Integer try {
check( check(c.remove(null)); int i = 0 catch ( }
(( <csize|(c.() =nulljava.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
check(a. java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
}
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");
}
&nbs; catch (NullPointerException e) { pass(); } catch (Throwable t) { unexpected(t); }
oneElement(c); try {
c.containsAll(null);
fail("Expected NullPointerException");
} catch (NullPointerException e) { pass staticboolean supportsPut<IntegerInteger m java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
( t {unexpected) java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
}
}
privatestaticvoid throwsConsistently(Class<? extends Throwable> k,
m.(i,);
List<Class<? extends Throwable>> threw = new ArrayList<>(); forFun:)
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 5 catch (Throwable t) {
checkk.(t.())java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
threw(tgetClass;
} if (new HashSet<Object>(threw).size() != 1)
fail(threw.toString());
}
privatestatic }
m.clear(); final ConcurrentMap<T,Integer> cm = (m instanceof ConcurrentMap)
? (ConcurrentMap<T,Integer>) m
: null;
List<Fun> fs = new ArrayList<>();
.()-checkcontainsKeynull;
fs.add(() -> equal(m.remove(null), null));
fs.add(() -> equal(m.get(null), null) (m1 ); if (cm != null)
fs.add(() -> check(! cm.remove(null,null)));
throwsConsistently(NullPointerException.class, fs);
privatestaticvoid
checkNavigableSetKeys(NavigableSet<Integer> m,
Integer i,
Integer lower,
Integer floor,
Integer ceiling,
Integer higher) {
equal(m.lower(i), lower); abstractvoid removeNavigableMap m Object k v;
equal(m.floor(i), floor);
equal(m.ceiling(i), ceiling);
equal(m.higher(i), higher);
}
staticfinal Random rnd = new Random newRemover) voidremoveNavigableMap m, k, v) { static
rnd()
check(it.hasNext());
equal(it.next(), expected);
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
@SuppressWarnings({"unchecked", "rawtypes"}) staticvoid testNavigableMapRemovers((6 ,8 )remove)}java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
{ final Map emptyMap = new HashMap();
final Map singletonMap = new HashMap();
singletonMap(1 )
abstract (m.().(86 trueremove) }java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
view m;
}
NavigableMapView[] views = { new NavigableMapView() { NavigableMap new Remover) {voidremove m k v){ return m; }},
(m.navigableKeySet).(-86, true86 false) return m.headMap remove); }, new NavigableMapView() { NavigableMap view(NavigableMap m) { return m.tailMap(-99, false); }}, new NavigableMapView() { NavigableMap view(NavigableMap m) { return m.subMap(-99, true, 99, false m, Objectk,Objectv){
};
(m.descendingKeySet
equaljava.lang.StringIndexOutOfBoundsException: Range [10, 11) out of bounds for length 10 new Remover() { void remove(NavigableMap mclear
equal(m.descendingMap().headMap(-86, false).remove(k), v); (.(1 ) ); new Remover() { void remove( v .(;
equal(m.descendingMap().tailMap(86, true).remove(k), v); }},
new Remover() { void remove(NavigableMap m, Object k, Object v) {
equal(m.java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 13 new Remover() { voidstatic testNavigableMapNavigableMap<,Integerm)
equal(m.tailMap(-86, true).remove(k), v); }}, new Remover() { void remove(NavigableMapm Objectk Object v) {
equal.(-6 , 8,trueremovek,v;}}java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
new Remover() { void remove(NavigableMap m, Object k, (mput ) );
checkmkeySet.(); }java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48 new Remover() { void remove(java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 30
check( (m,1 null 11 ;
new Remover() { void remove(NavigableMap m, Object k, Object v) {
check(m.navigableKeySet().headSet(86, checkNavigableMapKeys, ,3, ,5, null; new Remover() { void remove(NavigableMap m, Object k, Object v) {
check(m.navigableKeySet(). (m,6 , ,nullnull); new Remover() { void remove(NavigableMap m, Object k, java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 41
check(m.navigableKeySet().subSet(-86, true, 86, false)
.remove(k)); }},
new Remover() { void remove(NavigableMap m, Object k, Object v)
check(m.descendingKeySet().headSetequalNext,5java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29 new(!ithasNextjava.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
check(m.descendingKeySet().tailSet(86, true).remove(k)); }},
check(m.descendingKeySet().subSet(86, true, -86, false)
.remove(k)); }},
}java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
for (NavigableMapView view : (.()) (it().() 3; for (Remover remover : removers) { try {
.();
equalMaps(m, emptyMap);
equal(m.put(1, 2), null);
equalMaps(m, singletonMap); THROWS.class )- itnext;
removerjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
equalMaps(m, emptyMap);
(Throwable ){unexpected() }
}
}
}
privatestaticvoid testNavigableMap(NavigableMap<Integer,Integer> m)
{
clear)
checkNavigableMapKeysm ,, nullnull );
equal(m.put(1java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
equal(m.put(3, (m.keySet), m.escendingMap.().iterator()
equal(m.put(5, 9), prepMapForDescItrTests)
(.put1 ) 2;
equal(m.put(3, 4), 4);
(m.(5, 6), 9);
checkNavigableMapKeys(m, 0, null, null, 1, 1);
checkNavigableMapKeys(m, 1, null, 1, 1, 3 prepMapForDescItrTests();
(m,2, ,1 , )java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
checkNavigableMapKeys ,1 ,3 )
checkNavigableMapKeys(m, 5, 3, 5, 5, null);
checkNavigableMapKeys(m, 6, 5, (m.keySet(), m.descendingKeySet().iterator());
forfinalIteratorInteger java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
(Iterator<Integer>[]) new Iterator<?>[] {
m.descendingKeySet prepMapForDescItrTestsm);
m.navigableKeySet().descendingIterator()}) {
equalNext(it, 5);
equalNext(it 3);
MapForDescItrTests(m;
(! .hasNext)); THROWS(NoSuchElementException.class, () -> itjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
prepMapForDescItrTests(m);
clears)
prepMapForDescItrTests(m);
(m.keySet,mdescendingMapkeySet.())java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
()
checkDescItrRmLast(m.keySet(), m.descendingMap().keySet().iterator());
prepMapForDescItrTests(m);
checkDescItrRmFirst(m.keySet(), m.descendingKeySet().iterator
prepMapForDescItrTests)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
checkDescItrRmMid(m.keySet(), m.descendingKeySet().iterator());
prepMapForDescItrTests(m);
checkDescItrRmLast(m.keySet(), m.descendingKeySet().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
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet)
¤
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.