Skip to content

Commit 7934a43

Browse files
committed
Fix possible bugs:
- Fix incorrect "compare" method in the TimeZoneDefinition class - Fix NPE in the AttachmentCollection class - Fix incorrect casting in the ComplexPropertyDefinitionBase class
1 parent 9f011d1 commit 7934a43

3 files changed

Lines changed: 38 additions & 46 deletions

File tree

src/main/java/microsoft/exchange/webservices/data/property/complex/AttachmentCollection.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -383,30 +383,31 @@ public void validate() throws Exception {
383383
for (int attachmentIndex = 0; attachmentIndex < this.getAddedItems()
384384
.size(); attachmentIndex++) {
385385
final Attachment attachment = this.getAddedItems().get(attachmentIndex);
386-
if (attachment != null && attachment.isNew() && attachment instanceof FileAttachment) {
387-
// At the server side, only the last attachment with
388-
// IsContactPhoto is kept, all other IsContactPhoto
389-
// attachments are removed. CreateAttachment will generate
390-
// AttachmentId for each of such attachments (although
391-
// only the last one is valid).
392-
//
393-
// With E14 SP2 CreateItemWithAttachment, such request will only
394-
// return 1 AttachmentId; but the client
395-
// expects to see all, so let us prevent such "invalid" request
396-
// in the first place.
397-
//
398-
// The IsNew check is to still let CreateAttachmentRequest allow
399-
// multiple IsContactPhoto attachments.
400-
//
401-
if (((FileAttachment) attachment).isContactPhoto()) {
402-
if (contactPhotoFound) {
403-
throw new ServiceValidationException(
404-
"Multiple contact photos in attachment.");
386+
if (attachment != null) {
387+
if (attachment.isNew() && attachment instanceof FileAttachment) {
388+
// At the server side, only the last attachment with
389+
// IsContactPhoto is kept, all other IsContactPhoto
390+
// attachments are removed. CreateAttachment will generate
391+
// AttachmentId for each of such attachments (although
392+
// only the last one is valid).
393+
//
394+
// With E14 SP2 CreateItemWithAttachment, such request will only
395+
// return 1 AttachmentId; but the client
396+
// expects to see all, so let us prevent such "invalid" request
397+
// in the first place.
398+
//
399+
// The IsNew check is to still let CreateAttachmentRequest allow
400+
// multiple IsContactPhoto attachments.
401+
//
402+
if (((FileAttachment) attachment).isContactPhoto()) {
403+
if (contactPhotoFound) {
404+
throw new ServiceValidationException("Multiple contact photos in attachment.");
405+
}
406+
contactPhotoFound = true;
405407
}
406-
contactPhotoFound = true;
407408
}
409+
attachment.validate(attachmentIndex);
408410
}
409-
attachment.validate(attachmentIndex);
410411
}
411412
}
412413
}

src/main/java/microsoft/exchange/webservices/data/property/complex/time/TimeZoneDefinition.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.ArrayList;
3838
import java.util.Collections;
3939
import java.util.Comparator;
40+
import java.util.Date;
4041
import java.util.HashMap;
4142
import java.util.Iterator;
4243
import java.util.List;
@@ -109,20 +110,21 @@ public class TimeZoneDefinition extends ComplexProperty implements Comparator<Ti
109110
* positive number if x is greater than y.
110111
*/
111112
@Override
112-
public int compare(TimeZoneTransition x, TimeZoneTransition y) {
113+
public int compare(final TimeZoneTransition x, final TimeZoneTransition y) {
113114
if (x == y) {
114115
return 0;
115-
} else if (x instanceof TimeZoneTransition) {
116-
return -1;
117-
} else if (y instanceof TimeZoneTransition) {
118-
return 1;
119-
} else {
120-
AbsoluteDateTransition firstTransition = (AbsoluteDateTransition) x;
121-
AbsoluteDateTransition secondTransition = (AbsoluteDateTransition) y;
116+
} else if (x != null && y != null) {
117+
final AbsoluteDateTransition firstTransition = (AbsoluteDateTransition) x;
118+
final AbsoluteDateTransition secondTransition = (AbsoluteDateTransition) y;
122119

123-
return firstTransition.getDateTime().compareTo(
124-
secondTransition.getDateTime());
120+
final Date firstDateTime = firstTransition.getDateTime();
121+
final Date secondDateTime = secondTransition.getDateTime();
122+
123+
return firstDateTime.compareTo(secondDateTime);
124+
} else if (y == null) {
125+
return 1;
125126
}
127+
return -1;
126128
}
127129

128130
/**

src/main/java/microsoft/exchange/webservices/data/property/definition/ComplexPropertyDefinitionBase.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,15 @@ protected void internalLoadFromXml(EwsServiceXmlReader reader,
9999
boolean justCreated = getPropertyInstance(propertyBag, complexProperty);
100100
if (!justCreated && this.hasFlag(PropertyDefinitionFlags.UpdateCollectionItems,
101101
propertyBag.getOwner().getService().getRequestedServerVersion())) {
102-
ComplexProperty c = (ComplexProperty) complexProperty.getParam();
103-
if (complexProperty.getParam() instanceof ComplexProperty) {
104-
c.updateFromXml(reader, reader.getLocalName());
102+
Object c = complexProperty.getParam();
103+
if (c instanceof ComplexProperty) {
104+
((ComplexProperty) c).updateFromXml(reader, reader.getLocalName());
105105
}
106-
107-
108-
109106
} else {
110107
ComplexProperty c = (ComplexProperty) complexProperty.getParam();
111108
c.loadFromXml(reader, reader.getLocalName());
112109
}
113-
/*if (!propertyBag.tryGetValue(this, complexProperty) ||
114-
!this.hasFlag(PropertyDefinitionFlags.ReuseInstance)) {
115-
complexProperty.setParam(this.createPropertyInstance(propertyBag
116-
.getOwner()));
117-
}
118-
if (complexProperty.getParam() instanceof ComplexProperty) {
119-
ComplexProperty c = (ComplexProperty)complexProperty.getParam();
120-
c.loadFromXml(reader, reader.getLocalName());
121-
}*/
110+
122111
propertyBag.setObjectFromPropertyDefinition(this, complexProperty
123112
.getParam());
124113
}

0 commit comments

Comments
 (0)