@@ -348,42 +348,37 @@ protected void clearChangeLog() {
348348 */
349349 public void validate () throws Exception {
350350 // Validate all added attachments
351- boolean contactPhotoFound = false ;
352- for (int attachmentIndex = 0 ; attachmentIndex < this .getAddedItems ()
353- .size (); attachmentIndex ++) {
354- Attachment attachment = this .getAddedItems ().get (attachmentIndex );
355- if (attachment .isNew ()) {
356-
357- // At the server side, only the last attachment with
358- // IsContactPhoto is kept, all other IsContactPhoto
359- // attachments are removed. CreateAttachment will generate
360- // AttachmentId for each of such attachments (although
361- // only the last one is valid).
362- //
363- // With E14 SP2 CreateItemWithAttachment, such request will only
364- // return 1 AttachmentId; but the client
365- // expects to see all, so let us prevent such "invalid" request
366- // in the first place.
367- //
368- // The IsNew check is to still let CreateAttachmentRequest allow
369- // multiple IsContactPhoto attachments.
370- //
371- if (this .owner .isNew ()
372- && this .owner .getService ().getRequestedServerVersion ()
373- .ordinal () >= ExchangeVersion .Exchange2010_SP2
374- .ordinal ()) {
375- FileAttachment fileAttachment = (FileAttachment ) attachment ;
376-
377- if (fileAttachment .isContactPhoto ()) {
351+ if (this .owner .isNew ()
352+ && this .owner .getService ().getRequestedServerVersion ()
353+ .ordinal () >= ExchangeVersion .Exchange2010_SP2
354+ .ordinal ()) {
355+ boolean contactPhotoFound = false ;
356+ for (int attachmentIndex = 0 ; attachmentIndex < this .getAddedItems ()
357+ .size (); attachmentIndex ++) {
358+ final Attachment attachment = this .getAddedItems ().get (attachmentIndex );
359+ if (attachment != null && attachment .isNew () && attachment instanceof FileAttachment ) {
360+ // At the server side, only the last attachment with
361+ // IsContactPhoto is kept, all other IsContactPhoto
362+ // attachments are removed. CreateAttachment will generate
363+ // AttachmentId for each of such attachments (although
364+ // only the last one is valid).
365+ //
366+ // With E14 SP2 CreateItemWithAttachment, such request will only
367+ // return 1 AttachmentId; but the client
368+ // expects to see all, so let us prevent such "invalid" request
369+ // in the first place.
370+ //
371+ // The IsNew check is to still let CreateAttachmentRequest allow
372+ // multiple IsContactPhoto attachments.
373+ //
374+ if (((FileAttachment ) attachment ).isContactPhoto ()) {
378375 if (contactPhotoFound ) {
379376 throw new ServiceValidationException (
380377 Strings .MultipleContactPhotosInAttachment );
381378 }
382-
383379 contactPhotoFound = true ;
384380 }
385381 }
386-
387382 attachment .validate (attachmentIndex );
388383 }
389384 }
0 commit comments