java.nio.channels.CancelledKeyException#java.util.ConcurrentModificationException源码实例Demo

下面列出了java.nio.channels.CancelledKeyException#java.util.ConcurrentModificationException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-8-source   文件: ComodifiedRemove.java
public static
void main(String[] args) {
    List list = new LinkedList();
    Object o1 = new Integer(1);
    list.add(o1);
    ListIterator e = list.listIterator();
    e.next();
    Object o2 = new Integer (2);
    list.add(o2);

    try{
        e.remove();
    } catch (ConcurrentModificationException cme) {
        return;
    }

    throw new RuntimeException(
        "LinkedList ListIterator.remove() comodification check failed.");
}
 
源代码2 项目: coming   文件: Arja_00143_t.java
/**
 * Advance iterator one step further.
 * @exception ConcurrentModificationException if the map is modified during iteration
 * @exception NoSuchElementException if there is no element left in the map
 */
public void advance()
    throws ConcurrentModificationException, NoSuchElementException {

    if (referenceCount != count) {
        throw MathRuntimeException.createConcurrentModificationException(LocalizedFormats.MAP_MODIFIED_WHILE_ITERATING);
    }

    // advance on step
    current = next;

    // prepare next step
    try {
        while (states[++next] != FULL) {
            // nothing to do
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        next = -2;
        if (current < 0) {
            throw MathRuntimeException.createNoSuchElementException(LocalizedFormats.ITERATOR_EXHAUSTED);
        }
    }

}
 
@Override
@Nonnull
public final Object[] toArray() {
    int size = size();
    Object[] result = new Object[size];
    if (size == 0)
        return result;
    
    int resultIndex = 0;
    int mc = modCount();
    long free = freeValue;
    long[] keys = set;
    V[] vals = values;
    for (int i = (keys.length) - 1; i >= 0; i--) {
        long key;
        if ((key = keys[i]) != free) {
            result[(resultIndex++)] = new MutableEntry(mc, i, key, vals[i]);
        } 
    }
    if (mc != (modCount()))
        throw new ConcurrentModificationException();
    
    return result;
}
 
源代码4 项目: libreveris   文件: OmrFont.java
/**
 * This is the general paint method for drawing a symbol layout, at
 * a specified location, using a specified alignment.
 *
 * @param g         the graphics environment
 * @param layout    what: the symbol, perhaps transformed
 * @param location  where: the precise location in the display
 * @param alignment how: the way the symbol is aligned wrt the location
 */
public static void paint (Graphics2D g,
                          TextLayout layout,
                          Point location,
                          Alignment alignment)
{
    try {
        // Compute symbol origin
        Rectangle2D bounds = layout.getBounds();
        Point2D toTextOrigin = alignment.toTextOrigin(bounds);
        Point2D origin = new Point2D.Double(
                location.x + toTextOrigin.getX(),
                location.y + toTextOrigin.getY());

        // Draw the symbol
        layout.draw(g, (float) origin.getX(), (float) origin.getY());
    } catch (ConcurrentModificationException ignored) {
    } catch (Exception ex) {
        logger.warn("Cannot paint at " + location, ex);
    }
}
 
源代码5 项目: coding-snippets   文件: KolobokeLongIntHashMap.java
@Override
public boolean reverseRemoveAllFrom(IntSet s) {
    if ((KolobokeLongIntHashMap.ValueView.this.isEmpty()) || (s.isEmpty()))
        return false;
    
    boolean changed = false;
    int mc = modCount();
    long free = freeValue;
    long[] keys = set;
    int[] vals = values;
    for (int i = (keys.length) - 1; i >= 0; i--) {
        if ((keys[i]) != free) {
            changed |= s.removeInt(vals[i]);
        } 
    }
    if (mc != (modCount()))
        throw new ConcurrentModificationException();
    
    return changed;
}
 
源代码6 项目: gemfirexd-oss   文件: HARegionQueue.java
/**
 * this method is for transmission of DACE information with initial image state
 * in HARegions.  It should not be used for other purposes.  The map contains
 * only those entries that have no items queued.  This is used to prevent
 * replay of events in the new queue that have already been removed from this queue.
 */
public Map getEventMapForGII() {
  // fix for bug #41621 - concurrent modification exception while serializing event map
  Map<ThreadIdentifier, DispatchedAndCurrentEvents> events = this.eventsMap;
  do {
    HashMap result = new HashMap();
    try {
      for (Map.Entry<ThreadIdentifier, DispatchedAndCurrentEvents> entry: events.entrySet()) {
        if (entry.getValue().isCountersEmpty()) {
          result.put(entry.getKey(), entry.getValue());
        }
      }
      return result;
    } catch (ConcurrentModificationException e) {
      if (this.logger.fineEnabled()) {
        this.logger.fine("HARegion encountered concurrent modification exception while analysing event state - will try again");
      }
    }
  } while (true);
}
 
源代码7 项目: openjdk-jdk8u-backup   文件: ComodifiedRemove.java
public static
void main(String[] args) {
    List list = new LinkedList();
    Object o1 = new Integer(1);
    list.add(o1);
    ListIterator e = list.listIterator();
    e.next();
    Object o2 = new Integer (2);
    list.add(o2);

    try{
        e.remove();
    } catch (ConcurrentModificationException cme) {
        return;
    }

    throw new RuntimeException(
        "LinkedList ListIterator.remove() comodification check failed.");
}
 
public void sort(Comparator<? super E> c) {
    final ReentrantLock lock = l.lock;
    lock.lock();
    try {
        int lo = offset;
        int hi = offset + size;
        Object[] elements = expectedArray;
        if (l.getArray() != elements)
            throw new ConcurrentModificationException();
        int len = elements.length;
        if (lo < 0 || hi > len)
            throw new IndexOutOfBoundsException();
        Object[] newElements = Arrays.copyOf(elements, len);
        @SuppressWarnings("unchecked") E[] es = (E[])newElements;
        Arrays.sort(es, lo, hi, c);
        l.setArray(expectedArray = newElements);
    } finally {
        lock.unlock();
    }
}
 
源代码9 项目: libreveris   文件: SheetPainter.java
@Override
public boolean visit (SystemPart part)
{
    try {
        // Render the part starting barline, if any
        if (part.getStartingBarline() != null) {
            part.getStartingBarline()
                .renderLine(g);
        }
    } catch (ConcurrentModificationException ignored) {
    } catch (Exception ex) {
        logger.warn(
            getClass().getSimpleName() + " Error visiting " + part,
            ex);
    }

    return true;
}
 
源代码10 项目: phoebus   文件: ScanCommandTree.java
private TreeItem<ScanCommand> findTreeItem(final long address)
{
    if (address < 0)
        return null;
    while (true)
    {
        try
        {
            return findTreeItem(root.getChildren(), address);
        }
        catch (ConcurrentModificationException ex)
        {
            // XXX Avoid ConcurrentModificationException instead of catching and trying again?
            logger.log(Level.WARNING, "Scan tree needs to re-try lookup of command", ex);
        }
    }
}
 
源代码11 项目: android_9.0.0_r45   文件: ArrayMap.java
/**
 * Make the array map empty.  All storage is released.
 */
@Override
public void clear() {
    if (mSize > 0) {
        final int[] ohashes = mHashes;
        final Object[] oarray = mArray;
        final int osize = mSize;
        mHashes = EmptyArray.INT;
        mArray = EmptyArray.OBJECT;
        mSize = 0;
        freeArrays(ohashes, oarray, osize);
    }
    if (CONCURRENT_MODIFICATION_EXCEPTIONS && mSize > 0) {
        throw new ConcurrentModificationException();
    }
}
 
源代码12 项目: data-structures   文件: BinarySearchTreeTest.java
@Test(expected = ConcurrentModificationException.class)
public void concurrentModificationErrorRemovingPostOrder() {

  BinarySearchTree<Integer> bst = new BinarySearchTree<>();

  bst.add(1);
  bst.add(2);
  bst.add(3);

  Iterator<Integer> iter = bst.traverse(TreeTraversalOrder.POST_ORDER);

  while (iter.hasNext()) {
    bst.remove(2);
    iter.next();
  }
}
 
源代码13 项目: coding-snippets   文件: KolobokeLongIntHashMap.java
public boolean forEachWhile(LongPredicate predicate) {
    if (predicate == null)
        throw new NullPointerException();
    
    if (KolobokeLongIntHashMap.this.isEmpty())
        return true;
    
    boolean terminated = false;
    int mc = modCount();
    long free = freeValue;
    long[] keys = set;
    for (int i = (keys.length) - 1; i >= 0; i--) {
        long key;
        if ((key = keys[i]) != free) {
            if (!(predicate.test(key))) {
                terminated = true;
                break;
            } 
        } 
    }
    if (mc != (modCount()))
        throw new ConcurrentModificationException();
    
    return !terminated;
}
 
源代码14 项目: TencentKona-8   文件: ComodifiedRemove.java
public static
void main(String[] args) {
    List list = new LinkedList();
    Object o1 = new Integer(1);
    list.add(o1);
    ListIterator e = list.listIterator();
    e.next();
    Object o2 = new Integer (2);
    list.add(o2);

    try{
        e.remove();
    } catch (ConcurrentModificationException cme) {
        return;
    }

    throw new RuntimeException(
        "LinkedList ListIterator.remove() comodification check failed.");
}
 
源代码15 项目: dragonwell8_jdk   文件: CopyOnWriteArrayList.java
public void replaceAll(UnaryOperator<E> operator) {
    if (operator == null) throw new NullPointerException();
    final ReentrantLock lock = l.lock;
    lock.lock();
    try {
        int lo = offset;
        int hi = offset + size;
        Object[] elements = expectedArray;
        if (l.getArray() != elements)
            throw new ConcurrentModificationException();
        int len = elements.length;
        if (lo < 0 || hi > len)
            throw new IndexOutOfBoundsException();
        Object[] newElements = Arrays.copyOf(elements, len);
        for (int i = lo; i < hi; ++i) {
            @SuppressWarnings("unchecked") E e = (E) elements[i];
            newElements[i] = operator.apply(e);
        }
        l.setArray(expectedArray = newElements);
    } finally {
        lock.unlock();
    }
}
 
源代码16 项目: j2objc   文件: ArrayListTest.java
/**
 * java.util.ArrayList#trimToSize()
 */
public void test_trimToSize() {
    // Test for method void java.util.ArrayList.trimToSize()
    for (int i = 99; i > 24; i--)
        alist.remove(i);
    ((ArrayList) alist).trimToSize();
    assertEquals("Returned incorrect size after trim", 25, alist.size());
    for (int i = 0; i < alist.size(); i++)
        assertTrue("Trimmed list contained incorrect elements", alist
                .get(i) == objArray[i]);
    Vector v = new Vector();
    v.add("a");
    ArrayList al = new ArrayList(v);
    al.add("b");
    Iterator it = al.iterator();
    al.trimToSize();
    try {
        it.next();
        fail("should throw a ConcurrentModificationException");
    } catch (ConcurrentModificationException ioobe) {
        // expected
    }
}
 
源代码17 项目: incubator-retired-wave   文件: ConcurrentSetTest.java
public void testRemoveWhileLockedDoesNotCauseCme() {
  set.add(a);
  set.add(b);
  set.add(c);
  set.add(d);

  set.lock();
  try {
    // Removals to attempt on every iteration.
    String [] removals = new String [] {b, d, c, a};
    int toRemove = 0;
    for (String x : set) {
      set.remove(removals[toRemove++]);
    }
  } catch (ConcurrentModificationException e) {
    fail("removal during iteration caused CME");
  }
  set.unlock();
}
 
源代码18 项目: swellrt   文件: CopyOnWriteSetTest.java
public void testRemoveWhileIteratingDoesNotCauseCme() {
  set.add(a);
  set.add(b);
  set.add(c);
  set.add(d);

  try {
    // Removals to attempt on every iteration.
    String [] removals = new String [] {b, d, c, a};
    int toRemove = 0;
    for (String x : set) {
      set.remove(removals[toRemove++]);
    }
  } catch (ConcurrentModificationException e) {
    fail("removal during iteration caused CME");
  }
}
 
源代码19 项目: coding-snippets   文件: KolobokeLongIntHashMap.java
@Override
public final void forEach(@Nonnull
Consumer<? super Map.Entry<Long, Integer>> action) {
    if (action == null)
        throw new NullPointerException();
    
    if (KolobokeLongIntHashMap.EntryView.this.isEmpty())
        return ;
    
    int mc = modCount();
    long free = freeValue;
    long[] keys = set;
    int[] vals = values;
    for (int i = (keys.length) - 1; i >= 0; i--) {
        long key;
        if ((key = keys[i]) != free) {
            action.accept(new KolobokeLongIntHashMap.MutableEntry(mc, i, key, vals[i]));
        } 
    }
    if (mc != (modCount()))
        throw new ConcurrentModificationException();
    
}
 
源代码20 项目: appcan-android   文件: ELinkedList.java
public void add(ET object) {
    if (expectedModCount == list.modCount) {
        Link<ET> next = link.next;
        Link<ET> newLink = new Link<ET>(object, link, next);
        link.next = newLink;
        next.previous = newLink;
        link = newLink;
        lastLink = null;
        pos++;
        expectedModCount++;
        list.size++;
        list.modCount++;
    } else {
        throw new ConcurrentModificationException();
    }
}
 
源代码21 项目: hypergraphdb   文件: MyIdentityHashMap.java
Entry<K,V> nextEntry() { 
    if (modCount != expectedModCount)
        throw new ConcurrentModificationException();
    Entry<K,V> e = next;
    if (e == null) 
        throw new NoSuchElementException();
        
    Entry<K,V> n = e.next;
    Entry[] t = table;
    int i = index;
    while (n == null && i > 0)
        n = t[--i];
    index = i;
    next = n;
    return current = e;
}
 
源代码22 项目: coming   文件: Arja_00107_s.java
/**
 * Advance iterator one step further.
 * @exception ConcurrentModificationException if the map is modified during iteration
 * @exception NoSuchElementException if there is no element left in the map
 */
public void advance()
    throws ConcurrentModificationException, NoSuchElementException {

    if (referenceCount != count) {
        throw MathRuntimeException.createConcurrentModificationException(LocalizedFormats.MAP_MODIFIED_WHILE_ITERATING);
    }

    // advance on step
    current = next;

    // prepare next step
    try {
        while (states[++next] != FULL) {
            // nothing to do
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        next = -2;
        if (current < 0) {
            throw MathRuntimeException.createNoSuchElementException(LocalizedFormats.ITERATOR_EXHAUSTED);
        }
    }

}
 
public void forEach(Consumer<? super Long> action) {
    if (action == null)
        throw new NullPointerException();
    
    if (KolobokeLongObjectHashMap.this.isEmpty())
        return ;
    
    int mc = modCount();
    long free = freeValue;
    long[] keys = set;
    for (int i = (keys.length) - 1; i >= 0; i--) {
        long key;
        if ((key = keys[i]) != free) {
            action.accept(key);
        } 
    }
    if (mc != (modCount()))
        throw new ConcurrentModificationException();
    
}
 
源代码24 项目: data-structures   文件: BinarySearchTreeTest.java
@Test(expected = ConcurrentModificationException.class)
public void concurrentModificationErrorRemovingInOrderOrder() {

  BinarySearchTree<Integer> bst = new BinarySearchTree<>();

  bst.add(1);
  bst.add(2);
  bst.add(3);

  Iterator<Integer> iter = bst.traverse(TreeTraversalOrder.IN_ORDER);

  while (iter.hasNext()) {
    bst.remove(2);
    iter.next();
  }
}
 
源代码25 项目: coming   文件: Arja_0032_t.java
/**
 * Advance iterator one step further.
 * @exception ConcurrentModificationException if the map is modified during iteration
 * @exception NoSuchElementException if there is no element left in the map
 */
public void advance()
    throws ConcurrentModificationException, NoSuchElementException {

    if (referenceCount != count) {
        throw MathRuntimeException.createConcurrentModificationException(LocalizedFormats.MAP_MODIFIED_WHILE_ITERATING);
    }

    // advance on step
    current = next;

    // prepare next step
    try {
        while (states[++next] != FULL) {
            // nothing to do
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        next = -2;
        if (current < 0) {
            throw MathRuntimeException.createNoSuchElementException(LocalizedFormats.ITERATOR_EXHAUSTED);
        }
    }

}
 
源代码26 项目: astor   文件: OpenIntToDoubleHashMap.java
/**
 * Advance iterator one step further.
 * @exception ConcurrentModificationException if the map is modified during iteration
 * @exception NoSuchElementException if there is no element left in the map
 */
public void advance()
    throws ConcurrentModificationException, NoSuchElementException {

    if (referenceCount != count) {
        throw new ConcurrentModificationException();
    }

    // advance on step
    current = next;

    // prepare next step
    try {
        while (states[++next] != FULL) { // NOPMD
            // nothing to do
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        next = -2;
        if (current < 0) {
            throw new NoSuchElementException();
        }
    }

}
 
源代码27 项目: coding-snippets   文件: KolobokeLongIntHashMap.java
@Override
public void replaceAll(LongIntToIntFunction function) {
    if (function == null)
        throw new NullPointerException();
    
    if (KolobokeLongIntHashMap.this.isEmpty())
        return ;
    
    int mc = modCount();
    long free = freeValue;
    long[] keys = set;
    int[] vals = values;
    for (int i = (keys.length) - 1; i >= 0; i--) {
        long key;
        if ((key = keys[i]) != free) {
            vals[i] = function.applyAsInt(key, vals[i]);
        } 
    }
    if (mc != (modCount()))
        throw new ConcurrentModificationException();
    
}
 
源代码28 项目: astor   文件: OpenIntToFieldHashMap.java
/**
 * Advance iterator one step further.
 * @exception ConcurrentModificationException if the map is modified during iteration
 * @exception NoSuchElementException if there is no element left in the map
 */
public void advance()
    throws ConcurrentModificationException, NoSuchElementException {

    if (referenceCount != count) {
        throw new ConcurrentModificationException();
    }

    // advance on step
    current = next;

    // prepare next step
    try {
        while (states[++next] != FULL) {
            // nothing to do
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        next = -2;
        if (current < 0) {
            throw new NoSuchElementException();
        }
    }

}
 
源代码29 项目: ghidra   文件: AddressRangeMapDB.java
/**
 * @see ghidra.util.datastruct.IndexRangeIterator#hasNext()
 */
@Override
public boolean hasNext() {
	lock.acquire();
	try {
		if (expectedModCount != modCount)
			throw new ConcurrentModificationException();
		if (nextRec != null) {
			return true;
		}
		if (recIter != null) {
			try {
				return recIter.hasNext();
			}
			catch (IOException e) {
				errHandler.dbError(e);
			}
		}
		return false;
	}
	finally {
		lock.release();
	}
}
 
源代码30 项目: gatk   文件: SVIntervalTree.java
@Override
public Node<V> next() {
    if ( next == null ) {
        throw new NoSuchElementException("No next element.");
    }

    if ( next.wasRemoved() ) {
        next = (Node<V>)min(next.getInterval());
        if ( next == null ) {
            throw new ConcurrentModificationException("Current element was removed, and there are no more elements.");
        }
    }
    last = next;
    next = next.getNext();
    return last;
}