We use MongoDB and we get this error:
class java.lang.Double cannot be cast to class java.lang.Long (java.lang.Double and java.lang.Long are in module java.base of loader ‘bootstrap’)
The stacktrace:
{
"file": "Document.java",
"method": "getLong",
"line": 266,
"exact": false,
"location": "bson-3.11.0.jar",
"class": "org.bson.Document",
"version": "?"
},
{
"file": "Util.kt",
"method": "determineLastChanged",
"line": 11,
"exact": false,
"location": "foobar-backend-persist-2020.47.5.jar",
"class": "com.foobar.persist.trash.UtilKt",
"version": "?"
},
Our code:
// com.foobar.persist.trash.UtilKt
import org.bson.Document
internal fun determineLastChanged(trashDoc: Document): Long {
return trashDoc.getLong("_touched")
?: trashDoc.getLong("_created")
?: trashDoc.getDocument("_trash")?.getLong("deletedAt")
?: throw InternalTrashException("trash item without timestamp")
}
I know Java, but I am new to MongoDB. I worked with SQL in the past.
This error is rare, but if it happens, it is reproducible.
What could be the reason?