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 24618

Summary: List accessor not throwing IndexOutOfBoundsException
Product: java Reporter: Mark McKinlay <mckinlay>
Component: UnsupportedAssignee: issues@java <issues>
Status: VERIFIED FIXED    
Severity: blocker    
Priority: P3    
Version: 3.x   
Hardware: PC   
OS: Windows XP   
Issue Type: DEFECT Exception Reporter:

Description Mark McKinlay 2002-06-11 07:18:24 UTC
There appears to be a problem with the get(int) 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 get(int index) 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 followwing occurs:

if (list.size() == 0)
	// throws Exceptions correctly

if ((list.size() > 0) && (index < 0))
	// Returns element #0

if ((list.size() > 0) && (index >= list.size()))
	// throws Exceptions correctly

For Example the following code will not throw an 
IndexOutOfBoundsException

...
...
// Create a RecordType object which aggregates a List of 
RecordFields
RecordType recordType = pkg.getRecordType
().createRecordType();
List fields = recordType.getRecordFields();

// Create some field Objects in the List
RecordField field = pkg.getRecordField().createRecordField
();
field.setName("First Field");
recordType.getRecordFields().add(field);

field = pkg.getRecordField().createRecordField();
field.setName("Second Field");
recordType.getRecordFields().add(field);

field = pkg.getRecordField().createRecordField();
field.setName("Third Field");
recordType.getRecordFields().add(field);

try {
     RecordField rf = (RecordField)fields.get(-1);
     fail("Failed to throw OOB Exception");
} catch (IndexOutOfBoundsException aioobe) {
     // OK
}
Comment 1 Martin Matula 2002-06-12 11:13:12 UTC
I need a clarification. The recordField feature of 
RecordType class is a reference or an attribute? (I need 
to know this, because in each of these two cases it is 
handled by different implementation of the List interface).
Comment 2 Martin Matula 2002-06-12 11:47:58 UTC
OK, I think I have fixed it. Since I do not have your 
test, I haven't tested it, but I am quite sure that it is 
fixed. Please let me know if you try it (by either marking 
this issue as verified or reopened if it does not work). 
Fix is in the CVS.
Comment 3 Mark McKinlay 2002-12-20 00:39:49 UTC
I have tested and verified this fix.