Announcement Announcement Module
No announcement yet.
Test For Existing Values - List.isEmpty() doesn't seem to be reliable Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Test For Existing Values - List.isEmpty() doesn't seem to be reliable

    My application takes some "external key", checks to see if there's an existing entry for it and if not, generates a new unique id and creates an entry in the LDAP. If the "external key" is already in the ldap, then the corresponding id is returned. For example, given an external key of [email protected], the app will return a unique id like 698754125.

    Here's my code to test if the external key exists or not. I assume that if the key doesn't exist then tpinList.isEmpty() is true. But if the key DOES exist tpinList.isEmpty() should be false.

    My problem is this assumption doesn't also hold true. I'm getting tpinList.isEmpty() = true some times, even when there is data. This behavior appears to be completely random.

    Some times it works just as expected, then other times I get duplicate entries. I can test using the same external key and some times I get dups and some times I don't.

    Any ideas?

    Any other ways to test for existing records?

     private int lookupExternalKey(String externalKey) {
            List tpinList;
            Integer tpin;
            tpinList ="ou=identities","TAPexternalKey="+externalKey,SearchControls.SUBTREE_SCOPE,
                    new TPINAttributesMapper());
            if (tpinList.isEmpty()) {            
                tpin= new Integer(0);
            } else{
                tpin = (Integer) tpinList.get(0);
            return tpin.intValue();

  • #2
    Never mind. It turns out the real problem was elsewhere in the code and data related.