javaibm-domino

Does .remove on a document object result in a null?


In my java webagent I create a Document object. For example NotesDocument document = ...; later I use remove on this object:

document.remove(true);

Afterwards I want to check if document is null so any functions which normally operates on that document will not be executed

for example:

if(document != null){
System.out.println(document.getItemValueString("ID"));
}

It still goes into the if statement and its saying: NotesException: Object has been removed or recycled.

Is != null functioning in this case?


Solution

  • You already created a reference in the memory here.

    NotesDocument document = ...;
    
    ...
    
    // Even you called document.remove(), it still exists because the code does not destroy the object and reference itself.
    
    document.remove(true);
    
    // That is why this still works.
    if (document != null) {
        System.out.println(document.getItemValueString("ID"));
    }
    

    You can explicitly assign document = null; after you call remove() if that is what you are designated to do.

    Or

    You can check isDeleted() of document. e.g. if (!document.isDeleted()).

    Doc: https://www.ibm.com/support/knowledgecenter/en/SSVRGU_9.0.1/reference/r_domino_Document_IsDeleted.html