apache/seatunnel

MongoDB connector closeCurrentSplit() masks real errors with NullPointerException

Open

#10.999 geöffnet am 3. Juni 2026

Auf GitHub ansehen
 (2 Kommentare) (0 Reaktionen) (1 zugewiesene Person)Java (1.432 Forks)batch import
bughelp wanted

Repository-Metriken

Stars
 (6.897 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 23T) (98 gemergte PRs in 30 T)

Beschreibung

Summary

If the MongoDB source connector fails to create a cursor (due to connection, auth, or query error), the closeCurrentSplit() method in MongodbReader.java always throws a NullPointerException, masking the root MongoDB error. This affects jobs where parallelism > 1 or where only a single small split is generated. The outcome is that the real error never appears in logs—only the masking NPE.

Steps to Reproduce

  • Use SeaTunnel 2.3.13
  • Configure a MongoDB source with Zeta engine, parallelism > 1
  • Have a small collection or cause a MongoDB connection/query failure
  • Observe the stack trace:
java.lang.NullPointerException at org.apache.seatunnel.shade.com.google.common.base.Preconditions.checkNotNull(Preconditions.java:877)
  at org.apache.seatunnel.connectors.seatunnel.mongodb.source.reader.MongodbReader.closeCurrentSplit(MongodbReader.java:153)
  at org.apache.seatunnel.connectors.seatunnel.mongodb.source.reader.MongodbReader.pollNext(MongodbReader.java:104)

Impact

  • Users and deployers see an NPE and cannot diagnose the actual MongoDB connector problem.
  • Real database issues are hidden, causing confusion and unnecessary debug time.

Recommended Fix

Add a null check before attempting to close the cursor:

private void closeCurrentSplit() {
    if (cursor != null) {
        cursor.close();
        cursor = null;
    }
}

Additional Notes

Several downstream mitigations are helpful (force parallelism=1, set split-size high, run schema discovery before job submission) but do not address the issue for all cases.

A connector-side fix is required to allow real MongoDB errors to surface and avoid masking them with a NullPointerException.

Contributor Guide