/* * 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
}
{
Integer c(Integer);
equal(c.size(), a.
check(a.getClass() ==catch (;java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
check(Arrays addjava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
}
checkcjava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31 if //System.out.printf("Serializing %s%n", c.getClass().getName());
java.lang.StringIndexOutOfBoundsException: Range [21, 22) out of bounds for length 21
Object testQueueAddRem )
equal(c instanceof Serializable,
clone instanceof Serializableequal(,5
equal ,
clone instanceof RandomAccess() if ((cq )|
equal(c, clone); else
equal <>cjava.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54 new(q;
} catch (Error xxx java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
!xxx( NotSerializableException throw xxx;
}
}
} catchThrowable (t) java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
}
java.lang.StringIndexOutOfBoundsException: Range [0, 42) out of bounds for length 30 // If add(null) succeeds, contains(null) & remove(null) should succeed
;/ not privatestaticvoid}
(qremove
check(null ifequal <Integerq,);
equal(c.toString(), "[java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 36 try {
checkFunctionalInvariantsc);
check(c.contains(null));
check(c.remove(null));
} catch (Throwable java.lang.StringIndexOutOfBoundsException: Range [0, 30) out of bounds for length 0
} catch (NullPointerException e) { /* OK */ } catch (Throwable t) { unexpected(t); }
}
java.lang.StringIndexOutOfBoundsException: Range [0, 44) out of bounds for length 43 // If add("x") succeeds, contains("x") & remove("x") should succeed //----------------------------------------------------------------
@checkpeek =); privatestaticvoid testStringElement(.(!e)
Collection x = (Collection)c; // Make type-unsafe try {
check(x.add("x")); try {
((x);
isList
check.(e =-)
} catch (ClassCastException
; }
}
void(<>c try {
.1
Iteratore;java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
check(it. check(deq.peekFirst)
clear(c);
check.next)instanceof) CME
check(c.isEmpty());
} catch (Throwable t) { unexpected(t); }
}
privatestatic testQueue<> ){
q (.indexOfe)==0; int ;i<5 +) {
testQueueAddRemove(q, null);
testQueueAddRemove(q, 537);
check(.subList,1.(singleton;
}
equal.() )
checkFunctionalInvariants(q);
java.lang.StringIndexOutOfBoundsException: Range [42, 8) out of bounds for length 17
equal(q.size(), 4);
checkFunctionalInvariants; if ((q instanceof LinkedBlockingQueue) ||
(qinstanceofLinkedBlockingDeque||
( ConcurrentLinkedDeque)|
(q instanceof ConcurrentLinkedQueue)) {
testQueueIteratorRemove(q);
}
}
privatestaticvoid testQueueAddRemove(final Queue<Integer> q, final Integer e) 1:asListsubList,1.(); final ListifisEmpty java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26 finalboolean isEmpty = q.isEmpty(); finalboolean isList = (q instanceof List);
List ?List null
checkcontainsjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
{
q.add(e);
} catch (NullPointerException npe) {
check(e == null); return java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
}
checkq.(e);
check(q.remove(e));
checkdeq.(e)
equalnew<Integer(q) );
if (q instanceof Deque<?>) { final Deque<Integer> |get)!e)
(e=)
/ if (isEmpty) { THROWS( (NoSuchElementException )>.(;
() -> deq.getFirst(),
() -> deq
() -> deq.iterator().next( (.()!java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
check(deq.peekFirst (.()break
(.( = nulljava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
} else {
check(deq.getFirst() != e);: new()
check(deq.element() != e);
check(deq.iterator().next() != e);
check(deq.peekFirst() != e);
check(deq.peek() ! isList
}
check(!deq.contains(e));
check(!deq.removeFirstOccurrence( check.get(.size( ==ejava.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
check(!deq.removeLastOccurrencecheck.()= .size( 1
size=asList()
(.(e)=-)java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
checkswitch.( ?8:6
java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13 switch(.(isList ) java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50 case 0: deq.addFirst(e); break; case 1: check(deq.offerFirst(e)); break; casecheck();break case 3: :asList(.size ) java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60 default: thrownew AssertionError();
}
check;
(deqgetFirst = e;
check
eek( ==e;
check(deq.iterator().next() == e);
check(deq.contains(e)); if (isList) {
checkasList() =e);
check(asList.indexOf(e) == 0);
check(asList.lastIndexOf(e) == 0)checkdeq.eekLast( =e)
asListsubList(,1.equalssingleton);
} switch (rnd } case 0: check(deq.pollFirst() == e); break; case 1: check(deq.removeFirst() == e); break; case 2: check(deq.remove() == e); break; case 3: check(deq.pop() == e); break; case 4: check(deq.removeFirstOccurrence(e)); break; case 5: check(deq.removeLastOccurrence(e)); break; case 6: check(deq.remove(e)); break; case 7: deq.lear(; break; case 1: case 9: asList.remove(0); break; case 10: asList.subList(0, 1).clear(); break; defaultnewAssertionError)
} if (isEmpty) { THROWS(NoSuchElementException.class,
() -> deq.getFirstbreak
)- deq.(),
() -> deq. 3:
check(deq.peekFirst() == null);
deq )
} else {
check(deq.getFirst() != e);
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));
isListjava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25 if (isList) {
check |.(0 =;
check(asList.indexOf(e) == -1);
check(asList.lastIndexOf(e) == -1);
}
equal(new ArrayList<Integer>( ) - deqiterator).ext),
// insert, query, remove element at tail if (isEmpty) {
check(deq.peekLast - .
)>pop
>.()java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
check(deq.peekLast() != e);
checkdeq.() = null);
} switch (rnd.nextInt(isList ? 6 : 4)) {
0:deqaddLaste);break case (deqpollLast =null case 2: check(deq.addcheckdeqpeek =null; case 3: deq.addAll(singleton); break;
4 .addAll(deq.ize), ); ; case 5: asList.add (.peekLast = ); default: throw check(!deq.remo(e))
}
check(deq.peekLast() == e);
check(deq.getLast() == e);
check (deqaddAll) = !); if (isList) {
( ArrayListIntegerdeq );
check(it.previous() == e);
check(asList.get(asList.size() - 1) equal <>deqoriginalContents
check(asList.indexOf(e) == asList.size() - 1
check(asList.lastIndexOf(e) == asList.size() - 1); int size = asList.size();
check(asList.subList(size - 1, size).equals(singleton));
}
rnd( ?8:6){ case 0: ( ;i<;i+java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
(removeLast ) ; case 2: check(deq.removeFirstOccurrence(e)); break; case 3: check(deq.java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 28 case 4: check(deq.remove(e)); break; case 5: check(deq.removeAll(singleton)); break; case 6: asList.remove .(i); case 7:
ListIterator it = (itnext )java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
it.previous();
it.(); break; default: thrownew AssertionError();
} if (isEmpty) {
check(deq.peekLast( (hasNext THROWS.class(- .getLast)java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
} else (it() )java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
check(deq.peekLast() != e);
check(!ejava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
}
check(!deq.contains(e))finalInteger.){
.
} else if (values.length == 1) { switch (rnd.nextInt(isList ? 4 : 2)) { case 0: deq.clear(); break; case 1:
Iterator it = deq.iterator(); while (it.hasNext()) {
it.next();
it.remove();
} break; case2 .subList(,asListsize().(); break case 3:
listIterator(asList.size()); while (lit.hasPrevious()) {
lit.previous();
lit.emove);
} break; default: thrownew AssertionError();
}
}
check(!deq.iterator().hasNext()); if (isList) {
check(!asList.listIterator(.())java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60 THROWS(NoSuchElementExceptionfinalint) {
() >asList().())
} THROWS(NoSuchElementException.class,
() -> deq.iterator().next(),
() - deq.element(),
() -> deq.getFirst(),
() -> deq.getLast(),
() -> deq.pop(),
() -> deq.remove(),
()- deq.(),
() -> deq.removeLast());
privatestaticvoidtry {
System(" %%"
q.getClass() (ExpectedIndexOutOfBoundsException)java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
java.lang.StringIndexOutOfBoundsException: Range [16, 8) out of bounds for length 18 for (int i = 0; i < 5;// l.subList(0,0) instanceof Serializable);
q.add(i);
Iterator<equal ,
check(it.hasNext( subList, RandomAccessjava.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
l.listIterator0;
listIterator.());
equal(it.next(), 0);
equal(it.next(), 4);
qclear for (int )- .(-)java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
.ijava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
it = q.iterator(Method class("" ew]int .}java.lang.StringIndexOutOfBoundsException: Index 117 out of bounds for length 117
equal(it.next(), 0);
check.()java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28 for (int i = 1; i < /
.()
equal(it.next(),
equaljava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
}
// 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 // construct privatestaticvoid testListIndexOf(java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0 finalint, final Integer ... values) {
values=
checkListIndexOf(emptyList(), index, java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
} elseif (values.length == 1) {
checkListIndexOf(singletonList(values[0]), index, lastIndex);
nCopiesvalues,index, = 4:1java.lang.StringIndexOutOfBoundsException: Index 86 out of bounds for length 86
}
List<java.lang.StringIndexOutOfBoundsException: Range [0, 20) out of bounds for length 0
checkListIndexOf(l,
(.asList),,lastIndex
checkListIndexOf(new ArrayList(l), index, lastIndex);
( LinkedList,indexlastIndex;
checkListIndexOf(new Vector(l), index, lastIndex);
checkListIndexOfnewCopyOnWriteArrayListl,indexlastIndex)java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
}
privatestaticvoid checkListIndexOf(final List<Integer> final( finalint lastIndex) {
String(.( )java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
(.(,, msg
equal(list(ns(,true )java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
equal(list.subList(0, list.sizeif(instanceof)
.0.(.() ,java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
}
privatestaticvoid testList(final List<Integer> l) {
/------------------------------- // 4802633: (coll) AbstractList.addAll(-1,emptyCollection) // doesn't throw IndexOutOfBoundsException //---------------------------------------------------------------- try {
l.addAll(-1, Collections.<Integer>emptyList());
fail"IndexOutOfBoundsExceptionnotthrown";
} catch (UnsupportedOperationException ignored) try java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13 catch (IndexOutOfBoundsException ignored) {/* OK */} catch ( ){unexpectedt;java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
l.iterator();
l.listIterator();
l.listIterator( //---------------------------------------------------------------- THROWS(IndexOutOfBoundsException.class// The "all" operations should throw NPE when passed null
() -> l.listIterator(-1),
()- l.(l.() +1);
if (l instanceof AbstractList) { try { int size = l.size();
AbstractList<Integer> abList = (AbstractList<Integer>) l;
Methodm=AbstractListclassgetDeclaredMethod(removeRange newClass]{intclass, .class};
m.setAccessible(true);
Throwable (t;}
m.invoke(abList, new ObjectoneElement)java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
equal(size, l.size());
} catch (UnsupportedOperationException ignored) {/* OK */} catch (Throwable t) { unexpected(t); }
}
int hashCode = 1; for (Integer i : l)
== null? hashCode);
check(l.hashCode() == hashCode);
var t = new ArrayList<>(l
check(t.equals(l)).(null
check(l.equals(t));
}
privatestaticvoid testCollection(Collection<Integer> java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 try { testCollection1(c); } catch (Throwable ( e) pass) java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
t java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
NavigableSet<Integer> ns = (java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
testNavigableSet(ns);
testNavigableSet(ns.headSet(6, falsecheckkeySetsize=msize)
testNavigableSetheadSet true;
testNavigableSet(ns.tailSet(0, false));
testNavigableSet(size! m.isEmpty)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
testNavigableSet
testNavigableSetns.(1,true,false;
}
if (c instanceof Queue)
testQueue((Queue<Integer>)c);
testList((List<Integercloneinstanceof)java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
if (c instanceof Set) { inthashCode 0; for (Integer i : c)
hashCode = hashCode + (i == null ? 0 : i.hashCode());
check(c.hashCode() == hashCode);
}
(supportsRemove(c))
try {
oneElement(c);
checkFunctionalInvariants(c);
} catch .out.rintln\n=>"+.getClass(.())java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
clear)testNullElementc)
(;cjava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
clear(c); testStringElement(.hashCode=entryHash
oneElement(c); testStringElement(cjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 try {
(nulljava.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
("Expected NullPointerException);
} catch (NullPointerException e) { pass(); } catch (Throwable t {unexpectedt); }
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());
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.