This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 24620 - List.add(int, Object) not correctly throwing IndexOutOfBoundsExceptions
Summary: List.add(int, Object) not correctly throwing IndexOutOfBoundsExceptions
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 3.x
Hardware: PC Windows XP
: P3 blocker (vote)
Assignee: issues@java
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-06-11 07:48 UTC by Mark McKinlay
Modified: 2003-01-06 14:58 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark McKinlay 2002-06-11 07:48:41 UTC
There appears to be a problem with the add(int, Object) 
accessor method on List objects implemented by MDR.

We have MOF modelled a RecordType class which has on 
ordered collection of RecordField.

This is correctly specified in the generated RecordType 
JMI interface as:

List getRecordFields();

The contract of the List's add(int index, Object element) 
method is that it should throw an 
IndexOutOfBoundsException under the following conditions:

if ((index < 0 ) || (index > list.size()))
	throw new IndexOutOfBoundsException();

However for the underlying List implemented by MDR for a 
List defined in a JMI interface, the following occurs:

if (index < 0)
    // fails to throw IndexOutOfBoundsException

if ((list.size() > 0) && (index > list.size()))
    // processing fails in MDR with exception
    // Clearly this is being run as a junit test
    [junit] java.lang.Exception: Stack trace
    [junit]     at java.lang.Thread.dumpStack
(Thread.java:993)
    [junit]     at 
org.netbeans.mdr.util.TransactionMutex.leave
(TransactionMutex.java:151)
    [junit]     at 
org.netbeans.mdr.handlers.IndexSetWrapper.unlock
(IndexSetWrapper.java:46)
    [junit]     at 
org.netbeans.mdr.handlers.AEIndexUListWrapper.add
(AEIndexUListWrapper.java:68)
    [junit]     at 
net.agentis.apml.domain.RecordType_Test.testJMIOOBException
Add(RecordType_Test.java:360)
    [junit]     at java.lang.reflect.Method.invoke(Native 
Method)
    [junit]     at junit.framework.TestCase.runTest
(TestCase.java:166)
    [junit]     at junit.framework.TestCase.runBare
(TestCase.java:140)
    [junit]     at junit.framework.TestResult$1.protect
(TestResult.java:106)
    [junit]     at junit.framework.TestResult.runProtected
(TestResult.java:124)
    [junit]     at junit.framework.TestResult.run
(TestResult.java:109)
    [junit]     at junit.framework.TestCase.run
(TestCase.java:131)
    [junit]     at junit.framework.TestSuite.runTest
(TestSuite.java:173)
    [junit]     at junit.framework.TestSuite.run
(TestSuite.java:168)
    [junit]     at junit.framework.TestSuite.runTest
(TestSuite.java:173)
    [junit]     at junit.framework.TestSuite.run
(TestSuite.java:168)
    [junit] rolled back!
    [junit] Testsuite: net.agentis.apml.domain._AllTests
    [junit] Tests run: 249, Failures: 0, Errors: 1, Time 
elapsed: 7.094 sec
    [junit]
    [junit] Testcase: testJMIOOBExceptionAdd
(net.agentis.apml.domain.RecordType_Test):: Caused an ERROR
    [junit] null
    [junit]     at 
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunne
r.run(JUnitTestRunner.java:231)
    [junit] org.netbeans.mdr.util.DebugException
    [junit]     at 
org.netbeans.mdr.storagemodel.AssocEndIndexUList.add
(AssocEndIndexUList.java:101)
    [junit]     at 
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunne
r.main(JUnitTestRunner.java:409)
    [junit]     at 
org.netbeans.mdr.handlers.AEIndexUListWrapper.add
(AEIndexUListWrapper.java:65)
    [junit]     at 
net.agentis.apml.domain.RecordType_Test.testJMIOOBException
Add(RecordType_Test.java:360)
    [junit]     at java.lang.reflect.Method.invoke(Native 
Method)
    [junit]     at junit.framework.TestCase.runTest
(TestCase.java:166)
    [junit]     at junit.framework.TestCase.runBare
(TestCase.java:140)
    [junit]     at junit.framework.TestResult$1.protect
(TestResult.java:106)
    [junit]     at junit.framework.TestResult.runProtected
(TestResult.java:124)
    [junit]     at junit.framework.TestResult.run
(TestResult.java:109)
    [junit]     at junit.framework.TestCase.run
(TestCase.java:131)
    [junit]     at junit.framework.TestSuite.runTest
(TestSuite.java:173)
    [junit]     at junit.framework.TestSuite.run
(TestSuite.java:168)
    [junit]     at junit.framework.TestSuite.runTest
(TestSuite.java:173)
    [junit]     at junit.framework.TestSuite.run
(TestSuite.java:168)
    [junit]     at 
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunne
r.run(JUnitTestRunner.java:231)
    [junit]     at 
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunne
r.main(JUnitTestRunner.java:409)
    [junit]
Comment 1 Martin Matula 2002-06-12 11:31:38 UTC
Should be fixed in the main trunk.
Comment 2 Mark McKinlay 2002-12-20 00:50:22 UTC
Seems that this bug is still present.

I am using a CVS source build with QBUILD tag of 
QBE200210230100 (dated 23 October 2002)

The following JUnit Test fails: (we are using a RecordType 
object which contains a List of RecordField objects)

    public void testJMIOOBExceptionAdd()  throws Exception 
{
        // Can't run this test as it fais in MDR and we 
can't catch Exception
        // Left in so that we can test when netbeans bug 
is fixed.
        net.agentis.jmi.apml.RecordType recordType =
            getTestPackage().getModel().getApmlPackage
().getRecordType().createRecordType();
        List fields = recordType.getFields();
        net.agentis.jmi.apml.RecordField field =
            getTestPackage().getModel().getApmlPackage
().getRecordField().createRecordField();
        field.setName("First Field");
        assertEquals(0, recordType.getFields().size());
        try {
            fields.add(10, field);
            fail("Failed to throw OOB Exception");
        } catch (IndexOutOfBoundsException e) {
        }
    }


If the add(int, Object) method uses an index < 0, the 
method fails to throw an IndexOutOfBoundsException.

If the index >= fields.size() then the add() method throws 
a org.netbeans.mdr.util.DebugException
Comment 3 Martin Matula 2003-01-06 14:58:22 UTC
Fixed in main trunk.