pentaho/pentaho-kettle · error · KettleException
MailConnection.Error.FetchingMessages
Error message
MailConnection.Error.FetchingMessages
What it means
MailConnection.fetchNext() wraps any exception from indexing this.messages[getMessageNr()] into a KettleException with key MailConnection.Error.FetchingMessages. The typical cause is an ArrayIndexOutOfBoundsException when the internal counter runs past the end of the fetched message array, or a Message has been expunged.
Solutions
- Stop iterating when getMessageNr() >= getMessagesCount() instead of relying on fetchNext() to throw.
- Use the library's iteration loop (nextMessage/hasMore style helpers) rather than manual index arithmetic.
- Re-fetch the message list after external deletions, then restart the iteration.
Example fix
// before
while (true) {
connection.fetchNext(); // eventually out of bounds
process(connection.getMessage());
}
// after
for (int i = 0; i < connection.getMessagesCount(); i++) {
connection.fetchNext();
process(connection.getMessage());
} Defensive patterns
Strategy: validation
Validate before calling
if (connection.getMessagesCount() == 0 || connection.getMessageNr() >= connection.getMessagesCount()) { return; // nothing left to fetch } Try / catch
try { connection.fetchNext(); } catch (KettleException e) { logError("Fetch failed at index " + connection.getMessageNr(), e); break; } Prevention
- Bound iteration loops with getMessagesCount()
- Refetch messages after external expunges
- Prefer the library's iteration helpers over manual indexing
When it happens
Trigger: Calling fetchNext() more times than there are messages in the folder (getMessageNr() >= messages.length), or after the folder's messages were expunged so the array/sequence numbers are stale.
Common situations: Loop boundary off-by-one in a custom job/script driving MailConnection directly; another client deleted messages mid-scan making the cached array stale; folder re-opened and messages refetched with a different count.
Related errors
- DimensionLookup.Exception.ErrorDetectedInGettingKey
- Error executing forEachRow
- java.lang.NullPointerException (wrapped; row too short for…
- JobGetMailsFromPOP.Error.ClosingConnection
- JobGetMailsFromPOP.Error.ClosingFolder
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/c0a1c38f789e3e46.
Report an issue: GitHub.
Appendix: source
Thrown at plugins/email-messages/impl/src/main/java/org/pentaho/di/job/entries/getpop/MailConnection.java:1238
private void updateMessageNr() {
this.messagenr++;
}
private int getMessageNr() {
return this.messagenr;
}
/**
* Get next message.
*
* @throws KettleException
*/
public void fetchNext() throws KettleException {
updateMessageNr();
try {
this.message = this.messages[getMessageNr()];
} catch ( Exception e ) {
throw new KettleException( BaseMessages.getString( PKG, "MailConnection.Error.FetchingMessages" ), e );
}
}
/**
* Returns the current message.
*
* @return current message
*/
public Message getMessage() {
return this.message;
}
/**
* Returns the number of messages.
*
* @return messages count
*/
public int getMessagesCount() {View on GitHub (pinned to f3058517a1)