Author: noel Date: Tue May 31 14:29:16 2005 New Revision: 179283 URL: http://svn.apache.org/viewcvs?rev=179283&view=rev Log: JAMES-379. Apply patch from Stefano Bagnara. Serialization seems a stiff performance penalty, so we should revisit this issue when working on the Mailet API.
Modified: james/server/trunk/src/java/org/apache/james/core/MailImpl.java Modified: james/server/trunk/src/java/org/apache/james/core/MailImpl.java URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/core/MailImpl.java?rev=179283&r1=179282&r2=179283&view=diff ============================================================================== --- james/server/trunk/src/java/org/apache/james/core/MailImpl.java (original) +++ james/server/trunk/src/java/org/apache/james/core/MailImpl.java Tue May 31 14:29:16 2005 @@ -234,12 +234,20 @@ newMail.setRemoteHost(remoteHost); newMail.setRemoteAddr(remoteAddr); newMail.setLastUpdated(lastUpdated); - newMail.setAttributesRaw((HashMap) attributes.clone()); + try { + newMail.setAttributesRaw((HashMap) cloneSerializableObject(attributes)); + } catch (IOException e) { + // should never happen for in memory streams + newMail.setAttributesRaw(new HashMap()); + } catch (ClassNotFoundException e) { + // should never happen as we just serialized it + newMail.setAttributesRaw(new HashMap()); + } return newMail; } catch (MessagingException me) { // Ignored. Return null in the case of an error. } - return (Mail) null; + return null; } /** * Get the error message associated with this MailImpl. @@ -634,5 +642,26 @@ */ public boolean hasAttributes() { return !attributes.isEmpty(); + } + + + /** + * This methods provide cloning for serializable objects. + * Mail Attributes are Serializable but not Clonable so we need a deep copy + * + * @param input Object to be cloned + * @return the cloned Object + * @throws IOException + * @throws ClassNotFoundException + */ + private static Object cloneSerializableObject(Object o) throws IOException, ClassNotFoundException { + ByteArrayOutputStream b = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(b); + out.writeObject(o); + out.close(); + ByteArrayInputStream bi=new ByteArrayInputStream(b.toByteArray()); + ObjectInputStream in = new ObjectInputStream(bi); + Object no = in.readObject(); + return no; } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]