Loading

IMAP Matcher fails with java.lang.NullPointerException If Subject Of Email Is Null

Дата публикации: Oct 1, 2024
Решение

SYMPTOM

We can use an IMAP Matcher in application flow.
(Example)
User-added image

The application fails with java.lang.NullPointerException if Subject of an Email is Null. The error stack looks like something like below.

ERROR 2020-03-25 11:29:34,477 [[MuleRuntime].cpuLight.03: [sample].sample_Flow.CPU_LITE @540943a9] [event: 0-694c0a10-6ead-11ea-9914-005056ac7599] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler:
********************************************************************************
Message : Error while retrieving emails: null.
Element : sample_Flow/processors/2 @ sample:sample.xml:293 (For Each)
Element XML : <foreach doc:name="For Each" doc:id="c7e7b348-16e9-4235-bc0d-c01bbecb7214">
Error type : MULE:UNKNOWN
Payload Type : org.mule.runtime.core.internal.streaming.object.ManagedCursorIteratorProvider
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.NullPointerException
at java.util.regex.Matcher.getTextLength(Matcher.java:1283)
at java.util.regex.Matcher.reset(Matcher.java:309)
at java.util.regex.Matcher.<init>(Matcher.java:229)
at java.util.regex.Pattern.matcher(Pattern.java:1093)
at java.util.regex.Pattern.lambda$asPredicate$0(Pattern.java:5770)
at org.mule.extension.email.api.predicate.BaseEmailPredicateBuilder.lambda$build$0(BaseEmailPredicateBuilder.java:94

CAUSE

While the IMAP Matcher was dealing with Subjects of Emails and if there is an Email that has null Subject, "java.util.regex.Matcher.getTextLength" will detect NullPointerException as printed in the Stack.

SOLUTION

To filter Email Subject that will have null value, we can use Choise router to filter Subject and to check if the Subject is Not null.
(Example)

<choice doc:name="Choice" doc:id="3a6d013c-a100-42df-a14b-6664ef661611" >
				<when expression="#[(attributes.subject != null) and (attributes.subject contains 'Validated')]">
Номер статьи базы знаний

001123568

 
Загрузка
Salesforce Help | Article