[OJB-developers] Bug in TransactionImpl.java (Null Pointer Exception) in 0.9
Brought to you by:
thma
From: Galvin H. <gk...@ya...> - 2002-06-05 00:51:51
|
Encountered a null pointer exception that manifests itself when attempting to update a m:n relationship while using ODMG API - this is manifested in both TransactionImpl and ObjectReferenceDescriptor. In TransactionImpl: as it attempts to retrieve getforeignKeyfielddescriptors() from CollectionDescriptor(), the call can throw a null pointer exception. However, suppose that the CollectionDescriptor (ObjectReferenceDescriptor descendant) has its m_ForeignKeyFields not set or initialized. In fact, m_ForeignKeyFields are initialized only if addForeignKeyField() is called. Therefore, when getForeignKeyFieldDescriptors() is called, this code gets executed: Vector v = getForeignKeyFields(); /* WHAT HAPPENS IF v is NULL? NPE*/ // 2. get FieldDescriptor for each index from Class-descriptor Vector ret = new Vector(); Iterator iter = v.iterator(); while (iter.hasNext()) { Integer index = (Integer) iter.next(); ret.add(mif.getFieldDescriptorByIndex(index.intValue())); } TransactionImpl: ClassDescriptor itemCld = this.getBroker().getClassDescriptor(cds.getItemClass()); Object[] objPkValues = cld.getKeyValues(newTxObject); /* BEGIN NULL POINTER EXCEPTION THREAT */ FieldDescriptor[] itemFkFields = cds.getForeignKeyFieldDescriptors(itemCld); /* END NULL POINTER EXCEPTION THREAT */ while (colIterator.hasNext()) { Object item = colIterator.next(); // provide all items in collection attributes // with foreign key information before locking them! for (int j = 0; j < itemFkFields.length; j++) { FieldDescriptor fld = itemFkFields[j]; fld.getPersistentField().set(item, objPkValues[j]); } lock(item, lockMode); } Possible fix(es): 1) Have the m_ForeignKeyFields initialized and instantiated in the ObjectReferenceDescriptor() constructor 2) Modify TransactionImpl to detect whether or not a CollectionDescriptor has any fieldDescriptors at all - if not just call lock(item, lockMode). If so, provide all items in collection attributes with foreign key information before locking them. __________________________________________________ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com |