|
Typical POST then DOH moment. Extra defensive coding stops the synchronized block being entered all
the time. Playing at writing a unit test for this - I'm interested in whether this fixes a bug in a previous release or
just improves the code. Can't have a JUnit class implement Runnable it seems, so bit more code needed test-wise. Takayuki - does anything bad happen when it's not synchronized? Did you have an exception When I look at the three load method calls, nothing jumps out as likely to break even when running as Henri,
Yes, I had an exception related this issue. Here is an exception below. [2006/04/06 16:00:07.727][ERROR][ValidatorForm 112 line I use commons-validator 1.1.4 with Struts 1.2.7. In my opiniton, the three load methods needs synchronization. You are right. "if (validationMethod == null)" is added for performance. Regards, The Exception you posted is a bit weird, but I'm new to Validator so maybe it
screwed the output up. It's not possible to see what the actual error it hits is. Not that I don't think this should be applied - it makes sense to me and adding Following that up, really interested in seeing the non-messed up Exception. I
still don't see what the code might be falling over on. It is difficult to explain the multi-threading issue.
But I'm going to try! It's my understanding that exception was occured under the following procedure. 1) Both thread-A and thread-B have reached at line 663 of ValidatorAction. 657: private void loadParameterClasses(ClassLoader loader) 2) thread-A has reached at line 621 of ValidatorAction. 617: private void loadValidationMethod() throws ValidatorException { 3) thread-B has executed line 664. Then, parameterClasses variable has been 4) thread-A has executed line 624. Then, NoSuchMethodException was occured. Your description doesn't explain why an exception would be thrown, though. Yes,
in step 4, thread-A will be using the parameterClasses value that was set by thread-B in step 3, but so what? That's not going to hurt anything. We really do need to see an accurate stack trace. The one you have posted is In step 3, thread-B initialized parameterClasses as an array of null.
Then in step 4, thread-A couldn't find validateId method because parameterClasses was incorrect. If you thought that this problem was depends on the configuration, I say "No". I putted a whole stack trace. The information was chipped off at line 627. A) ValidatorException was thrown because NoSuchMethodException was catched at OK, I get it now. But rather than take the performance hit of synchronising this
chunk of code, it would be simpler and faster to just use a local variable inside of the loadParameterClasses method, until all the parameter classes have been loaded, and then assign that to this.parameterClasses. The problem is happening because we are directly assigning to the member variable before the array has been initialised. Martin,
I'm glad that you got it. I considered whether I can make the synchronizatioin block would be smaller. I believe that this change is advisability because synchronization won't be used Thanks, Fixed in the 2006-05-04 nightly build.
I've done both. That is, applied the suggested patch as well as used a local Re-openned and the set to "Resolved Fixed" again to correct "resolution" which was lost in Bugzilla --> JIRA conversion
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
Given that the methods it calls are all defensive and private, it's not needed. Dunno if it's worth adding -
doesn't seem like it can hurt.