ews-java-api icon indicating copy to clipboard operation
ews-java-api copied to clipboard

EmailMessageSchema.Body is unusable because it has a null name

Open srusso opened this issue 10 years ago • 2 comments

ItemView view = new ItemView(pageSize, offset);
view.setPropertySet(
     new PropertySet(
        ItemSchema.Subject,
        EmailMessageSchema.Body
     )
  );
  return this.exchangeService.findItems(WellKnownFolderName.Inbox, view);

This causes:

Exception in thread "main" microsoft.exchange.webservices.data.exception.ServiceRequestException: The request failed. The property null can't be used in FindItem request.
at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:80)
at microsoft.exchange.webservices.data.core.request.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:158)
at microsoft.exchange.webservices.data.core.ExchangeService.findItems(ExchangeService.java:984)
at microsoft.exchange.webservices.data.core.ExchangeService.findItems(ExchangeService.java:1028)
at microsoft.exchange.webservices.data.core.ExchangeService.findItems(ExchangeService.java:1103)
...
...

And in fact this

System.out.println(EmailMessageSchema.Body.getName());

prints null. Is this the desired behaviour?

srusso avatar Apr 24 '15 14:04 srusso

EmailMessage.Body is a ComplexProperty. You cannot use a ComplexProperty in a FindItem request if memory serves.

That being said, this one brings us to another "What the heck is this??" moment. The name field in the PropertyDefintion class is not set via the constructor. It's set by calling ServiceObjectSchema.initializeSchemaPropertyNames(), which is a hideous abomination that was bound to cause problems thanks to the inexplicable use of reflection. I can't come up with a single plausible explanation as to why this mess was ever summoned into existence.

Let's fix it and set the name property without the reflective horror. However, in this case, it's only affecting the message in the exception.

Noblebrown avatar Apr 24 '15 19:04 Noblebrown

hmm seems that ServiceObjectSchema.allSchemaTypes.getMember() is just an empty list when it is tried being iterated. The reason could be because this has been commented. A small test with the uncommented code (78 - 94) solves the problem and the name is set. @Noblebrown you are completely right with your statement. Unfortunately the requested change might be huge and the side effects are somehow incalculable. So maybe we should also think of a short-termed solution here?

serious6 avatar Apr 27 '15 17:04 serious6