ConcurrentModificationException on ActionErrors

2003-12-31 Thread Richard Mixon (qwest)
I have a Struts action that is trying to show all of the errors that might occur from 
either or both of two subordinate methods. The
code looks like:

  ...
  ActionErrors errors = new ActionErrors();
  ActionErrors errors1 = null;
  ActionErrors errors2 = null;

  Obj1 obj1 = new Obj1();
  Obj2 obj2 = new Obj2();

  obj1.method1();
  errors1 = obj1.getErrors();
  if (!errors1.isEmpty()) {
  errors.add(errors1);
  }

  obj2.method2();
  errors2 = obj2.getErrors();
  if (!errors2.isEmpty()) {
  errors.add(errors1);
  }
  ...

Problem is I get the ConcurrentModificationException when I try and do either of the 
errors.add methods above. Methods
method1/method2 are pretty vanilla, just doing some database work and accumulating any 
errors in an associated ActionErrors.

I've searched the archives but only found one or two references to 
ConcurrentModificationException and they did not involve
ActionErrors. Any ideas or help is appreciated.

- Richard



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ConcurrentModificationException on ActionErrors

2003-12-31 Thread Paul-J Woodward

I don't know what is causing the exact error from your code snippet, but a 
ConcurrentModificationException is thrown when you try to modify a list on which you 
have an iterator.

See here: 
http://java.sun.com/j2se/1.4.1/docs/api/java/util/ConcurrentModificationException.html

Paul

Global Equity Derivatives Technology
Deutsche Bank [/]
Office  +44 (0)20 754 55458
Mobile +44 (0)7736 299483
Fax  +44 (0)20 7547 2752



   
   
 
  Richard Mixon   
   
 
  (qwest) To:   Struts Users Mailing List 
[EMAIL PROTECTED]
  
  [EMAIL PROTECTED]cc:
   
  
  iz  Subject:  
ConcurrentModificationException on ActionErrors
   
   
   
 
  31/12/2003 15:36 
   
 
  Please respond to
   
 
  Struts Users
   
 
  Mailing List
   
 
   
   
 
   
   
 




I have a Struts action that is trying to show all of the errors that might occur from 
either or both of two subordinate methods. The
code looks like:

  ...
  ActionErrors errors = new ActionErrors();
  ActionErrors errors1 = null;
  ActionErrors errors2 = null;

  Obj1 obj1 = new Obj1();
  Obj2 obj2 = new Obj2();

  obj1.method1();
  errors1 = obj1.getErrors();
  if (!errors1.isEmpty()) {
  errors.add(errors1);
  }

  obj2.method2();
  errors2 = obj2.getErrors();
  if (!errors2.isEmpty()) {
  errors.add(errors1);
  }
  ...

Problem is I get the ConcurrentModificationException when I try and do either of the 
errors.add methods above. Methods
method1/method2 are pretty vanilla, just doing some database work and accumulating any 
errors in an associated ActionErrors.

I've searched the archives but only found one or two references to 
ConcurrentModificationException and they did not involve
ActionErrors. Any ideas or help is appreciated.

- Richard



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






--

This e-mail may contain confidential and/or privileged information. If you are not the 
intended recipient (or have received this e-mail in error) please notify the sender 
immediately and destroy this e-mail. Any unauthorized copying, disclosure or 
distribution of the material in this e-mail is strictly forbidden.



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: ConcurrentModificationException on ActionErrors

2003-12-31 Thread Richard Mixon (qwest)
Paul,

Thanks I had seen the exception javadoc. An in one of my subordinate methods I do have 
a logging snippet that uses an Iterator to
display ALL of the contents of the ActionErrors. And I imagine that my subsequent use 
of the ActionErrors.add(ActionErrors) method
also uses an Iterator to enumerate the ActionError objects. Is there anyway to close 
the first Iterator so that it does not cause
this conflict?

Thanks again - Richard

-Original Message-
From: Paul-J Woodward [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 31, 2003 8:51 AM
To: Struts Users Mailing List
Subject: Re: ConcurrentModificationException on ActionErrors



I don't know what is causing the exact error from your code snippet, but a 
ConcurrentModificationException is thrown when you try to
modify a list on which you have an iterator.

See here: 
http://java.sun.com/j2se/1.4.1/docs/api/java/util/ConcurrentModificationException.html

Paul

Global Equity Derivatives Technology
Deutsche Bank [/]
Office  +44 (0)20 754 55458
Mobile +44 (0)7736 299483
Fax  +44 (0)20 7547 2752




  Richard Mixon
  (qwest) To:   Struts Users Mailing List 
[EMAIL PROTECTED]
  [EMAIL PROTECTED]cc:
  iz  Subject:  
ConcurrentModificationException on ActionErrors

  31/12/2003 15:36
  Please respond to
  Struts Users
  Mailing List






I have a Struts action that is trying to show all of the errors that might occur from 
either or both of two subordinate methods. The
code looks like:

  ...
  ActionErrors errors = new ActionErrors();
  ActionErrors errors1 = null;
  ActionErrors errors2 = null;

  Obj1 obj1 = new Obj1();
  Obj2 obj2 = new Obj2();

  obj1.method1();
  errors1 = obj1.getErrors();
  if (!errors1.isEmpty()) {
  errors.add(errors1);
  }

  obj2.method2();
  errors2 = obj2.getErrors();
  if (!errors2.isEmpty()) {
  errors.add(errors1);
  }
  ...

Problem is I get the ConcurrentModificationException when I try and do either of the 
errors.add methods above. Methods
method1/method2 are pretty vanilla, just doing some database work and accumulating any 
errors in an associated ActionErrors.

I've searched the archives but only found one or two references to 
ConcurrentModificationException and they did not involve
ActionErrors. Any ideas or help is appreciated.

- Richard



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






--

This e-mail may contain confidential and/or privileged information. If you are not the 
intended recipient (or have received this
e-mail in error) please notify the sender immediately and destroy this e-mail. Any 
unauthorized copying, disclosure or distribution
of the material in this e-mail is strictly forbidden.



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ConcurrentModificationException on ActionErrors

2003-12-31 Thread Kris Schneider
It almost sounds like your code isn't handling errors1 and/or errors2 in a
thread-safe manner. ConcurrentModificationException will be thrown if one thread
is in the proces of iterating over a collection and another thread modifies that
collection. ActionMessages.add(ActionMessages) will iterate over both the arg's
properties and the messages for each property, so there's certainly the
potential for the error you're seeing. Can you provide some more detail on how
your code is organized?

BTW, not sure if it's a c/p error, but you've got:

if (!errors2.isEmpty()) {
  errors.add(errors1);  // shouldn't that be errors2?
}

Quoting Richard Mixon (qwest) [EMAIL PROTECTED]:

 I have a Struts action that is trying to show all of the errors that might
 occur from either or both of two subordinate methods. The
 code looks like:
 
   ...
   ActionErrors errors = new ActionErrors();
   ActionErrors errors1 = null;
   ActionErrors errors2 = null;
 
   Obj1 obj1 = new Obj1();
   Obj2 obj2 = new Obj2();
 
   obj1.method1();
   errors1 = obj1.getErrors();
   if (!errors1.isEmpty()) {
   errors.add(errors1);
   }
 
   obj2.method2();
   errors2 = obj2.getErrors();
   if (!errors2.isEmpty()) {
   errors.add(errors1);
   }
   ...
 
 Problem is I get the ConcurrentModificationException when I try and do either
 of the errors.add methods above. Methods
 method1/method2 are pretty vanilla, just doing some database work and
 accumulating any errors in an associated ActionErrors.
 
 I've searched the archives but only found one or two references to
 ConcurrentModificationException and they did not involve
 ActionErrors. Any ideas or help is appreciated.
 
 - Richard

-- 
Kris Schneider mailto:[EMAIL PROTECTED]
D.O.Tech   http://www.dotech.com/

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ConcurrentModificationException on ActionErrors

2003-12-31 Thread Ben Anderson
Could you show the implementation(s) of your ObjX.getErrors() methods.  I'm 
guessing there's probably a better way to do what you're trying to do.

It probably has something to do with the implementation of:
http://jakarta.apache.org/struts/api/org/apache/struts/action/ActionMessages.html#add(org.apache.struts.action.ActionMessages)
which calls:
http://jakarta.apache.org/struts/api/org/apache/struts/action/ActionMessages.html#properties()
which returns an Iterator, which, as described below probably throws your 
exception.
It sounds like the ActionErrors instance you're adding may be the same one 
you're trying to add it to.
-Ben

From: Paul-J Woodward [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Subject: Re: ConcurrentModificationException on ActionErrors
Date: Wed, 31 Dec 2003 15:51:01 +
I don't know what is causing the exact error from your code snippet, but a 
ConcurrentModificationException is thrown when you try to modify a list on 
which you have an iterator.

See here: 
http://java.sun.com/j2se/1.4.1/docs/api/java/util/ConcurrentModificationException.html

Paul

Global Equity Derivatives Technology
Deutsche Bank [/]
Office  +44 (0)20 754 55458
Mobile +44 (0)7736 299483
Fax  +44 (0)20 7547 2752



  Richard Mixon
  (qwest) To:   Struts Users 
Mailing List [EMAIL PROTECTED]
  [EMAIL PROTECTED]cc:
  iz  Subject:  
ConcurrentModificationException on ActionErrors

  31/12/2003 15:36
  Please respond to
  Struts Users
  Mailing List




I have a Struts action that is trying to show all of the errors that might 
occur from either or both of two subordinate methods. The
code looks like:

  ...
  ActionErrors errors = new ActionErrors();
  ActionErrors errors1 = null;
  ActionErrors errors2 = null;
  Obj1 obj1 = new Obj1();
  Obj2 obj2 = new Obj2();
  obj1.method1();
  errors1 = obj1.getErrors();
  if (!errors1.isEmpty()) {
  errors.add(errors1);
  }
  obj2.method2();
  errors2 = obj2.getErrors();
  if (!errors2.isEmpty()) {
  errors.add(errors1);
  }
  ...
Problem is I get the ConcurrentModificationException when I try and do 
either of the errors.add methods above. Methods
method1/method2 are pretty vanilla, just doing some database work and 
accumulating any errors in an associated ActionErrors.

I've searched the archives but only found one or two references to 
ConcurrentModificationException and they did not involve
ActionErrors. Any ideas or help is appreciated.

- Richard



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--

This e-mail may contain confidential and/or privileged information. If you 
are not the intended recipient (or have received this e-mail in error) 
please notify the sender immediately and destroy this e-mail. Any 
unauthorized copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
_
Working moms: Find helpful tips here on managing kids, home, work —  and 
yourself.   http://special.msn.com/msnbc/workingmom.armx

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: ConcurrentModificationException on ActionErrors

2003-12-31 Thread Richard Mixon (qwest)
Ben,

The implementation is a pretty simple getter. The ActionErrors object is built by 
the call to obj1.method1().


/**
 *  Get ActionErrors object
 */
public ActionErrors getErrors() {
return errors;
}

The actual code for obj1 is very large (1900 lines) and of course 99% is not relevant 
to the issue (but which 1% is :) ) so I
hesitate to attach it.

The obj1 and obj2 objects (not their actual names) are actually DAO objects that take 
as input a Struts form bean and update and
add/chg/delete the corresponding database object. All of the edit, error and mapping 
code is included (generated by XDoclet) so its
huge (actually compiles small, but being generated its quite verbose).

If I cannot figure this out, I will go back to a simpler strategy. I had weanted to 
let the user see all errors at once, rather than
showing them some, having them correct them and then showing them more.

Thanks again - Richard

-Original Message-
From: Ben Anderson [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 31, 2003 9:04 AM
To: [EMAIL PROTECTED]
Subject: Re: ConcurrentModificationException on ActionErrors


Could you show the implementation(s) of your ObjX.getErrors() methods.  I'm
guessing there's probably a better way to do what you're trying to do.

It probably has something to do with the implementation of:
http://jakarta.apache.org/struts/api/org/apache/struts/action/ActionMessages.html#add(org.apache.struts.action.ActionMessages)
which calls:
http://jakarta.apache.org/struts/api/org/apache/struts/action/ActionMessages.html#properties()
which returns an Iterator, which, as described below probably throws your
exception.
It sounds like the ActionErrors instance you're adding may be the same one
you're trying to add it to.
-Ben

From: Paul-J Woodward [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Subject: Re: ConcurrentModificationException on ActionErrors
Date: Wed, 31 Dec 2003 15:51:01 +


I don't know what is causing the exact error from your code snippet, but a
ConcurrentModificationException is thrown when you try to modify a list on
which you have an iterator.

See here:
http://java.sun.com/j2se/1.4.1/docs/api/java/util/ConcurrentModificationException.html

Paul

Global Equity Derivatives Technology
Deutsche Bank [/]
Office  +44 (0)20 754 55458
Mobile +44 (0)7736 299483
Fax  +44 (0)20 7547 2752




   Richard Mixon
   (qwest) To:   Struts Users
Mailing List [EMAIL PROTECTED]
   [EMAIL PROTECTED]cc:
   iz  Subject:
ConcurrentModificationException on ActionErrors

   31/12/2003 15:36
   Please respond to
   Struts Users
   Mailing List






I have a Struts action that is trying to show all of the errors that might
occur from either or both of two subordinate methods. The
code looks like:

   ...
   ActionErrors errors = new ActionErrors();
   ActionErrors errors1 = null;
   ActionErrors errors2 = null;

   Obj1 obj1 = new Obj1();
   Obj2 obj2 = new Obj2();

   obj1.method1();
   errors1 = obj1.getErrors();
   if (!errors1.isEmpty()) {
   errors.add(errors1);
   }

   obj2.method2();
   errors2 = obj2.getErrors();
   if (!errors2.isEmpty()) {
   errors.add(errors1);
   }
   ...

Problem is I get the ConcurrentModificationException when I try and do
either of the errors.add methods above. Methods
method1/method2 are pretty vanilla, just doing some database work and
accumulating any errors in an associated ActionErrors.

I've searched the archives but only found one or two references to
ConcurrentModificationException and they did not involve
ActionErrors. Any ideas or help is appreciated.

- Richard



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






--

This e-mail may contain confidential and/or privileged information. If you
are not the intended recipient (or have received this e-mail in error)
please notify the sender immediately and destroy this e-mail. Any
unauthorized copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


_
Working moms: Find helpful tips here on managing kids, home, work —  and
yourself.   http://special.msn.com/msnbc/workingmom.armx


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional

RE: ConcurrentModificationException on ActionErrors

2003-12-31 Thread Richard Mixon (qwest)
Kris,

Thanks - I do not think I have multiple threads involved, but certaily multiple 
Iterators may be hanging around that are not GC'd
yet.

And yes that was a typo. Because the real code is so huge, I created a simple example 
to paste in and obviously did not compile it
:)

 - Richard

-Original Message-
From: Kris Schneider [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 31, 2003 9:01 AM
To: Struts Users Mailing List
Subject: Re: ConcurrentModificationException on ActionErrors


It almost sounds like your code isn't handling errors1 and/or errors2 in a
thread-safe manner. ConcurrentModificationException will be thrown if one thread
is in the proces of iterating over a collection and another thread modifies that
collection. ActionMessages.add(ActionMessages) will iterate over both the arg's
properties and the messages for each property, so there's certainly the
potential for the error you're seeing. Can you provide some more detail on how
your code is organized?

BTW, not sure if it's a c/p error, but you've got:

if (!errors2.isEmpty()) {
  errors.add(errors1);  // shouldn't that be errors2?
}

Quoting Richard Mixon (qwest) [EMAIL PROTECTED]:

 I have a Struts action that is trying to show all of the errors that might
 occur from either or both of two subordinate methods. The
 code looks like:

   ...
   ActionErrors errors = new ActionErrors();
   ActionErrors errors1 = null;
   ActionErrors errors2 = null;

   Obj1 obj1 = new Obj1();
   Obj2 obj2 = new Obj2();

   obj1.method1();
   errors1 = obj1.getErrors();
   if (!errors1.isEmpty()) {
   errors.add(errors1);
   }

   obj2.method2();
   errors2 = obj2.getErrors();
   if (!errors2.isEmpty()) {
   errors.add(errors1);
   }
   ...

 Problem is I get the ConcurrentModificationException when I try and do either
 of the errors.add methods above. Methods
 method1/method2 are pretty vanilla, just doing some database work and
 accumulating any errors in an associated ActionErrors.

 I've searched the archives but only found one or two references to
 ConcurrentModificationException and they did not involve
 ActionErrors. Any ideas or help is appreciated.

 - Richard

--
Kris Schneider mailto:[EMAIL PROTECTED]
D.O.Tech   http://www.dotech.com/

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: ConcurrentModificationException on ActionErrors

2003-12-31 Thread Kris Schneider
Although it's possible to generate that exception from within the same thread,
it's usually triggered by multiple threads accessing the same collection. In
general, if you grab an iterator, then modify the underlying collection, and
then call iter.next(), you'll see that exception. Having multiple iterators
shouldn't be an issue - you don't explicitly close an iterator like a database
connection. It will be GC-ed just like any other object. The problem really
boils down to modifying the backing collection while iteration is in progress.
By in progress, I mean doing something like calling iter.next(), not that
there's just an iterator instance lying around.

Quoting Richard Mixon (qwest) [EMAIL PROTECTED]:

 Kris,
 
 Thanks - I do not think I have multiple threads involved, but certaily
 multiple Iterators may be hanging around that are not GC'd
 yet.
 
 And yes that was a typo. Because the real code is so huge, I created a simple
 example to paste in and obviously did not compile it
 :)
 
  - Richard
 
 -Original Message-
 From: Kris Schneider [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, December 31, 2003 9:01 AM
 To: Struts Users Mailing List
 Subject: Re: ConcurrentModificationException on ActionErrors
 
 
 It almost sounds like your code isn't handling errors1 and/or errors2 in a
 thread-safe manner. ConcurrentModificationException will be thrown if one
 thread
 is in the proces of iterating over a collection and another thread modifies
 that
 collection. ActionMessages.add(ActionMessages) will iterate over both the
 arg's
 properties and the messages for each property, so there's certainly the
 potential for the error you're seeing. Can you provide some more detail on
 how
 your code is organized?
 
 BTW, not sure if it's a c/p error, but you've got:
 
 if (!errors2.isEmpty()) {
   errors.add(errors1);  // shouldn't that be errors2?
 }
 
 Quoting Richard Mixon (qwest) [EMAIL PROTECTED]:
 
  I have a Struts action that is trying to show all of the errors that
 might
  occur from either or both of two subordinate methods. The
  code looks like:
 
...
ActionErrors errors = new ActionErrors();
ActionErrors errors1 = null;
ActionErrors errors2 = null;
 
Obj1 obj1 = new Obj1();
Obj2 obj2 = new Obj2();
 
obj1.method1();
errors1 = obj1.getErrors();
if (!errors1.isEmpty()) {
errors.add(errors1);
}
 
obj2.method2();
errors2 = obj2.getErrors();
if (!errors2.isEmpty()) {
errors.add(errors1);
}
...
 
  Problem is I get the ConcurrentModificationException when I try and do
 either
  of the errors.add methods above. Methods
  method1/method2 are pretty vanilla, just doing some database work and
  accumulating any errors in an associated ActionErrors.
 
  I've searched the archives but only found one or two references to
  ConcurrentModificationException and they did not involve
  ActionErrors. Any ideas or help is appreciated.
 
  - Richard
 
 --
 Kris Schneider mailto:[EMAIL PROTECTED]
 D.O.Tech   http://www.dotech.com/

-- 
Kris Schneider mailto:[EMAIL PROTECTED]
D.O.Tech   http://www.dotech.com/

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]