Issue Details (XML | Word | Printable)

Key: JAMES-474
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Blocker Blocker
Assignee: Stefano Bagnara
Reporter: Stefano Bagnara
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
JAMES Server

NullPointerException and bodymessage lost with weird configurations in message spooling

Created: 08/Apr/06 03:48 AM   Updated: 21/Nov/07 08:31 AM
Return to search
Component/s: James Core
Affects Version/s: 2.3.0
Fix Version/s: 2.3.0

Time Tracking:
Not Specified

Resolution Date: 16/Jun/06 11:51 PM


 Description  « Hide
Under particular condition the new MimeMessageWrapper optimization code seems to loose the message source.
I've already created a unittest for this and I remove the optimization, but this need a fix.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #392373 Fri Apr 07 19:50:54 UTC 2006 bago Test and temporary fix for a rare but critical NPE in MimeMessageWrapper (JAMES-474)
Files Changed
MODIFY /james/server/trunk/src/test/org/apache/james/core/MimeMessageFromSharedStreamTest.java
MODIFY /james/server/trunk/src/java/org/apache/james/core/MimeMessageWrapper.java
MODIFY /james/server/trunk/src/java/org/apache/james/core/MimeMessageCopyOnWriteProxy.java
MODIFY /james/server/trunk/src/test/org/apache/james/core/MimeMessageTest.java

Martijn Brinkers added a comment - 08/Apr/06 05:58 PM
Should'nt access to some (or all?) variables like modified, bodyModified etc. be synchronized?

The method:

public synchronized void setDataHandler(DataHandler arg0) throws MessagingException

changes modified and bodyModified and it's synchonized but all other access to modified and bodyModified is not synchronized. The constructor for example checks bodyModified but access to bodyModified is not synchronized. A context switch can occur in setDataHandler just before bodyModified is set to true which results in an 'out-of-sync' between what the constructor 'sees' and what setDataHandler 'sees'.

A related question. Why are all variables protected and not private using getters/setters? Having them private with getters/setters would make it easier to add thread safety.


Stefano Bagnara added a comment - 09/Apr/06 12:51 AM
Martijn, thank you for your comment.

This issue is not related to synchronization, btw I think I should review the synchronization in the MimeMessageWrapper because I changed it a lot and I didn't check the synchronizations lately. The problem here is that 2 MimeMessageWrapper ends up sharing a single MimeMessageSource and the MimeMessageSource.dispose() call by one of them remove the source to the other message: I'm deciding wether to remove the optimization (as I did in the "fast fix") or introduce counters to know how much messages share the source.

I'm not sure that the issue you point about non synchronized property access in the constructor is valid, because I don't see how a content switch can happen during the constructor (can another thread get access to the object before the constructor is completely executed?).

They are not public, I think that field exists for a reason and getter/setter are not always the best thing. Btw, in this case I simply followed the style used in MimeMessage, as we extend that object and MimeMessage provide access to its internal via protected fields.

Repository Revision Date User Message
ASF #392749 Sun Apr 09 15:06:34 UTC 2006 bago Added conservative synchronization to MimeMessageWrapper (JAMES-474)
Hint by Martijn Brinkers
Files Changed
MODIFY /james/server/trunk/src/java/org/apache/james/core/MimeMessageWrapper.java

Norman Maurer added a comment - 12/Apr/06 04:04 AM
Is this error caused by this? And any idea why it is not happen everytime when run the junit test:

testEmptyMessage(org.apache.james.smtpserver.SMTPServerTest)
java.lang.NullPointerException
at org.apache.james.core.MimeMessageCopyOnWriteProxy.getSize(MimeMessageCopyOnWriteProxy.java:234)
at org.apache.james.smtpserver.SMTPServerTest.testEmptyMessage(SMTPServerTest.java:197)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:228)
at junit.framework.TestSuite.run(TestSuite.java:223)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

Repository Revision Date User Message
ASF #393430 Wed Apr 12 10:32:33 UTC 2006 bago Removed NPE in SMTPServerTest (see JAMES-474)
Files Changed
MODIFY /james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java
MODIFY /james/server/trunk/src/test/org/apache/james/test/mock/james/MockMailServer.java

Stefano Bagnara added a comment - 12/Apr/06 05:39 PM
Adding a "System.gc();" before the getSize I'm able to reproduce your NPE.
I will check the problem as soon as possible.

Stefano Bagnara added a comment - 12/Apr/06 05:53 PM
The problem is in the SMTPServerTest: SMTPHandler dispose the Mail as soon as it processed it. The current test implementation doesn't clone the message when receiving it but share the message with the SMTPHandler. When SMTPHandler dispose the MailImpl object, in turn the MimeMessageCopyOnWriteProxy.dispose is called and the wrapped mimemessage is set to null.

Stefano Bagnara made changes - 15/Apr/06 09:44 PM
Field Original Value New Value
Priority Critical [ 2 ] Blocker [ 1 ]
Stefano Bagnara made changes - 27/Apr/06 05:06 PM
Status Open [ 1 ] In Progress [ 3 ]
Stefano Bagnara made changes - 28/Apr/06 02:57 AM
Fix Version/s 2.3.0a2 [ 12310795 ]
Stefano Bagnara added a comment - 28/Apr/06 05:59 AM
Marking this as resolved because the current trunk should no more been affected by this bug.
Btw we should link to this issue and open a new "Improvement" issue to find a solution to reenable the optimizations provided by the "commented" code.

Stefano Bagnara made changes - 28/Apr/06 05:59 AM
Status In Progress [ 3 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Repository Revision Date User Message
ASF #404773 Sun May 07 14:46:33 UTC 2006 bago Refactored the MimeMessageCopyOnWriteProxyTest and added a proof of a bug (maybe related to JAMES-474)
Files Changed
MODIFY /james/server/trunk/src/test/org/apache/james/core/MimeMessageCopyOnWriteProxyTest.java

Repository Revision Date User Message
ASF #404780 Sun May 07 14:59:13 UTC 2006 bago Possible fix for an NPE whose test has been just added to MimeMessageCopyOnWriteProxy (maybe related to JAMES-474)
Files Changed
MODIFY /james/server/trunk/src/java/org/apache/james/core/MimeMessageCopyOnWriteProxy.java

Repository Revision Date User Message
ASF #404782 Sun May 07 15:19:44 UTC 2006 bago One more test for the MMCoW object (still investigating on JAMES-474)
Files Changed
MODIFY /james/server/trunk/src/test/org/apache/james/core/MimeMessageCopyOnWriteProxyTest.java

Repository Revision Date User Message
ASF #404783 Sun May 07 15:21:10 UTC 2006 bago Previous commit was not a solution, trying a new one after a new failing test has been added (JAMES-474)
Files Changed
MODIFY /james/server/trunk/src/java/org/apache/james/core/MimeMessageCopyOnWriteProxy.java

Repository Revision Date User Message
ASF #404802 Sun May 07 17:18:20 UTC 2006 bago Few more tests (work in progress) for NPE and IOExceptions in message cloning/sharing code (JAMES-474)
Files Changed
MODIFY /james/server/trunk/src/test/org/apache/james/core/MimeMessageWrapperTest.java
MODIFY /james/server/trunk/src/java/org/apache/james/core/MimeMessageWrapper.java
MODIFY /james/server/trunk/src/test/org/apache/james/core/MimeMessageCopyOnWriteProxyTest.java
MODIFY /james/server/trunk/src/java/org/apache/james/core/MimeMessageUtil.java
MODIFY /james/server/trunk/src/test/org/apache/james/core/MimeMessageTest.java

Stefano Bagnara added a comment - 07/May/06 11:06 PM
Not sure this bug was opened for this exact NPE, but I found a new problem while working on the Handler refactoring, added tests and a possible fix.

I reopen this because this probably should be merged on 2.3.0a2 before the release, but need more testing.

Stefano Bagnara made changes - 07/May/06 11:06 PM
Resolution Fixed [ 1 ]
Status Resolved [ 5 ] Reopened [ 4 ]
Stefano Bagnara added a comment - 12/May/06 03:14 PM
Let's say this is closed now.

Stefano Bagnara made changes - 12/May/06 03:14 PM
Resolution Fixed [ 1 ]
Status Reopened [ 4 ] Resolved [ 5 ]
Fix Version/s 2.3.0a2 [ 12310795 ]
Fix Version/s 2.3.0a3 [ 12311010 ]
Repository Revision Date User Message
ASF #406350 Sun May 14 15:10:45 UTC 2006 bago Core mimemessage handling changes to remove random NPE: merged r404773-r404802 to 2.3 branch (JAMES-474)
Files Changed
MODIFY /james/server/branches/v2.3/src/java/org/apache/james/core/MimeMessageWrapper.java
MODIFY /james/server/branches/v2.3/src/test/org/apache/james/core/MimeMessageCopyOnWriteProxyTest.java
MODIFY /james/server/branches/v2.3/src/java/org/apache/james/core/MimeMessageCopyOnWriteProxy.java
MODIFY /james/server/branches/v2.3/src/java/org/apache/james/core/MimeMessageUtil.java
MODIFY /james/server/branches/v2.3/src/test/org/apache/james/core/MimeMessageTest.java
MODIFY /james/server/branches/v2.3/src/test/org/apache/james/core/MimeMessageWrapperTest.java

Norman Maurer added a comment - 16/Jun/06 10:35 PM
After upgrading from james-2.3a2 to james-2.3.0b1 we see again that the headers get lost after do changes on headers. So the bug is probaly still here :-(
We wrote a mailet to log all headers and it shows that the headers get truncated after the fist change of headers is done in a mailet!

We tested it with mysql-4.1 and mysql conector 3.1.13 and 5.0-beta. Os is debian ubuntu with java 1.5




Norman Maurer made changes - 16/Jun/06 10:35 PM
Resolution Fixed [ 1 ]
Status Resolved [ 5 ] Reopened [ 4 ]
Stefano Bagnara added a comment - 16/Jun/06 11:51 PM
The problem was not related to this issue.
I thought this at first, too.. but I think it was there previously. Opened JAMES-538 for the "new" problem

Stefano Bagnara made changes - 16/Jun/06 11:51 PM
Resolution Fixed [ 1 ]
Status Reopened [ 4 ] Resolved [ 5 ]
Danny Angus added a comment - 21/Nov/07 08:31 AM
Closing issue fixed in released version.

Danny Angus made changes - 21/Nov/07 08:31 AM
Status Resolved [ 5 ] Closed [ 6 ]