[SNMP4J] ConcurrentModificationException in tabular data

Fabian Nart fabian.nart at ergon.ch
Tue Mar 21 09:28:57 CET 2006


Hi Frank

Thanks for the quick answer. But I have to admit I don't see the point 
in your fix. The problem seems to be that somewhere in the system there 
is a reference to our TableListener AFTER TableUtils.GetTable() returns 
which is used to update the TableListner's List called rows. This 
problem is not solved by cloning the rows BEFORE returning them. The 
change that I made to my code looks following:

--- Code ----------------------------------------------------
TableUtils tu=new TableUtils(_snmp, new DefaultPDUFactory(PDU.GETBULK));

List rows= tu.getTable(_target, oids, lowerBoundIndex, upperBoundIndex);
List rows2= new ArrayList(rows); // inserted line

for (Iterator i= rows2.iterator(); i.hasNext();) {
   TableEvent row= (TableEvent) i.next();
   (...)
}
--- / Code --------------------------------------------------

This doesn't help for sure but it minimizes the possibility of a conflict.

Cheers, Fabian


Frank Fock wrote:
> Hi Fabian,
> 
> Indeed something strange must have happened.
> The following change within the TableUtils
> class should avoid the exception:
> 
>   class InternalTableListener implements TableListener {
> 
>     private List rows = new LinkedList();
> 
>     public boolean next(TableEvent event) {
>       rows.add(event);
>       return true;
>     }
> 
>     public synchronized void finished(TableEvent event) {
>       if ((event.getStatus() != TableEvent.STATUS_OK) ||
>           (event.getIndex() != null)) {
>         rows.add(event);
>       }
>       rows = new ArrayList(rows);
>       notify();
>     }
> 
>     public List getRows() {
>       return rows;
>     }
>   }
> 
> The change should be also in the next nightly build
> available from http://www.agentpp.org/~katzwww/snapshot/
> (Note: The CVS snapshots are still experimental)
> 
> Best regards,
> Frank
> 
> Fabian Nart wrote:
>> Hi,
>>
>> I'm having trouble while retrieving tabular SNMP-data and proceed it 
>> with an Iterator. When I iterate through the received list of 
>> tableevents I get a ConcurrentModificationException. However, I'm 
>> pretty sure that my code doesn't touch the list at all (see code below).
>>
>> The exception occurs in the line marked with ###. The _snmp is a 
>> reference to the single Snmp-object in my system. Is it possible that 
>> somewhere inside SNMP4j the returned List is modified after I've 
>> created my Iterator? (I've looked at the source but didn't see 
>> anything suspect, but maybe I overlooked something)
>>
>> Unfortunately, I cannot reproduce this failure, it just showed up a 
>> few times -- but it should never occur, of course.
>>
>> I'm grateful for any comments
>> Fabian
>>
>>
>> --- Code ----------------------------------------------------
>>
>> TableUtils tu= new TableUtils(_snmp, new DefaultPDUFactory(PDU.GETBULK));
>>
>> List rows= tu.getTable(_target, oids, lowerBoundIndex, upperBoundIndex);
>>
>> for (Iterator i= rows.iterator(); i.hasNext();) {
>>   TableEvent row= (TableEvent) i.next(); // ###
>>   (...)
>> }
>>
>> --- / Code --------------------------------------------------
>> _______________________________________________
>> SNMP4J mailing list
>> SNMP4J at agentpp.org
>> http://lists.agentpp.org/mailman/listinfo/snmp4j
> 


-- 
fabian.nart at ergon.ch  +41 44 268 89 70
Ergon Informatik AG, Kleinstrasse 15, CH-8008 Zürich
http://www.ergon.ch
______________________________________________________________
e r g o n    smart people - smart software



More information about the SNMP4J mailing list