When opening a document in the Notes Java API (Notes.jar), there's an internal logic to check whether that document has been opened and not recycled before.
So for example in this snippet
Database db = session.getDatabase("Server1/Org", "test.nsf");
Document doc1 = db.getDocumentByUNID("3CABC08F5934F9F7A3EADACC42AAD52E");
Document doc2 = db.getDocumentByUNID("3CABC08F5934F9F7A3EADACC42AAD52E");
doc1.recycle();
doc2.getFirstItem("TEST");
both doc1 and doc2 share the same internal C handle. This might have made sense years ago when only few free handles were available but that number has been increased.
There's no reference counting involved, so recycling one doc instance also recycles the second instance which is pretty bad when both docs were opened in different parts of a large codebase.
So the last line of my snippet, accessing the "TEST" item, will throw an exception.
Apart from causing "Object has been removed or recycled" exceptions, sharing doc handles also prevents developers from opening the doc a second time to compare old/new item values after a change or run operations like a temporary richtext-to-MIME conversions on a doc (case in point, in one of our applications we want to mirror a "body" richtext item as "bodymime" on doc save).
Using the C API or alternative APIs like Domino JNA handles are not shared. Please add a switch on Session level, e.g. Session.setReuseDocumentHandles(boolean) to disable sharing in Notes.jar as well.
Karsten Lehmann, Mindoo GmbH