Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8e94506558ad21ce38abe48961ea739d99569937 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * Copyright (c) 2010-2012, 2016 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Caspar De Groot - initial API and implementation
 */
package org.eclipse.emf.cdo.tests.bugzilla;

import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.tests.AbstractCDOTest;
import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.tests.model1.PurchaseOrder;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CommitException;

import java.util.List;

/**
 * Bug 302414, bug 316713 - ArrayIndexOutOfBoundsException in CDOListFeatureDeltaImpl
 *
 * @author Caspar De Groot
 */
public class Bugzilla_302414_Test extends AbstractCDOTest
{
  public void test1() throws CommitException
  {
    CDOSession session = openSession();
    CDOTransaction tx = session.openTransaction();
    CDOResource r1 = tx.createResource(getResourcePath("/r1")); //$NON-NLS-1$

    Company company = getModel1Factory().createCompany();
    r1.getContents().add(company);
    tx.commit();

    List<PurchaseOrder> list = company.getPurchaseOrders();

    PurchaseOrder foo = getModel1Factory().createPurchaseOrder();
    list.add(foo);
    list.remove(foo);

    PurchaseOrder bar = getModel1Factory().createPurchaseOrder();
    list.add(bar);

    for (int i = 0; i < 10; i++)
    {
      company.getPurchaseOrders().add(getModel1Factory().createPurchaseOrder());
    }

    try
    {
      list.remove(bar);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      e.printStackTrace();
      fail("Should not have thrown " + e.getClass().getName());
    }

    tx.close();
    session.close();
  }

  public void test2() throws CommitException
  {
    CDOSession session = openSession();
    CDOTransaction tx = session.openTransaction();
    CDOResource r1 = tx.createResource(getResourcePath("/r1")); //$NON-NLS-1$

    Company company = getModel1Factory().createCompany();
    r1.getContents().add(company);
    tx.commit();

    List<PurchaseOrder> list = company.getPurchaseOrders();

    try
    {
      for (int i = 0; i < 20; i++)
      {
        PurchaseOrder foo1 = getModel1Factory().createPurchaseOrder();
        PurchaseOrder foo2 = getModel1Factory().createPurchaseOrder();
        list.add(foo1);
        list.add(foo2);
        list.remove(foo1);
      }
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      fail("Should not have thrown " + e.getClass().getName());
    }

    tx.close();
    session.close();
  }
}

Back to the top