Yesterday I stumbled upon a nasty thing in the Java Notes API. I had a loop through all ACL enties of a database I wanted to collect and "pimp" with my own class to get a readable info per entry for levels and user types. I also wanted to collect the options for each entry e.g. DBACL_CREATE_DOCUMENTS. My code looked similar to this one:
import lotus.domino.ACL;
import lotus.domino.ACLEntry;
import lotus.domino.Database;
import lotus.domino.NotesException;
import lotus.domino.NotesFactory;
import lotus.domino.NotesThread;
import lotus.domino.Session;
public class ACLEntryTest {
public static void main(String[] args) {
try {
NotesThread.sinitThread();
Session session = NotesFactory.createSession();
Database db = session.getDatabase("", "names.nsf");
ACL acl = db.getACL();
ACLEntry entry = acl.getFirstEntry();
while (entry != null) {
// do something with the entry
System.out.println(entry.getName() + " - " + entry.getLevel());
// access other ACL infos
// int options = db.queryAccessPrivileges(entry.getName());
// get the next one
entry = acl.getNextEntry(entry);
}
} catch (NotesException e) {
e.printStackTrace();
} finally {
NotesThread.stermThread();
}
}
}
Notice the commented line where I access the ACL options for the current entry. This code will run and loop through all entries. If you uncomment the line to get the options the loop will fail after the first entry with this exception:
-Default- - 0
NotesException: Argument has been removed or recycled
at lotus.domino.local.ACL.getNextEntry(Unknown Source)
at ACLEntryTest.main(ACLEntryTest.java:27)
Where the heck is the entry gone? It seems that the entry object is also used when calling the query method of the database - afterwards the pointer is lost and I get the problem.