Why driver ignores the readPreference set by the application?

I recently found that when I dump mongodb command into the log I saw the mode shown as primaryPreferred though my connection string has “readPreference=primary”.

… omitted … “lsid”: {“id”: {“$binary”: {“base64”: “R4hz5QZCTRSL1v0DzzokkQ==”, “subType”: “04”}}}, “$readPreference”: {“mode”: “primaryPreferred”}}

I traced down to the source code mongo-java-driver/driver-core/src/main/com/mongodb/internal/connection/CommandMessage.java at main · mongodb/mongo-java-driver · GitHub and mongo-java-driver/driver-core/src/main/com/mongodb/internal/connection/CommandMessage.java at a6d7d1d6c042b46969ed6cc509ad36e809130d00 · mongodb/mongo-java-driver · GitHub.

It turned out that CommandMessage is changing read preference to primaryPreferred even if I use primary readPreference.

if (readPreference != null) {
if (!readPreference.equals(primary())) {
extraElements.add(new BsonElement(“$readPreference”, readPreference.toDocument()));
} else if (isDirectConnectionToReplicaSetMember()) {
extraElements.add(new BsonElement(“$readPreference”, primaryPreferred().toDocument()));
}
}

This is puzzling to say the least. Can someone explain why and more importantly how to let the driver honor my setting? Thanks!