From 66faa7347addc7e471fae7110da349485008adf2 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Tue, 24 Mar 2009 12:58:17 +0000
Subject: [PATCH] Fix for issue 3826 (Exception in control panel LDAP browser)

---
 opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/browser/BrowserController.java     |   17 ++++++++++++++---
 opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java |   28 +++++++++++++++++++---------
 2 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/browser/BrowserController.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/browser/BrowserController.java
index 644c48a..039b2cf 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/browser/BrowserController.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/browser/BrowserController.java
@@ -258,8 +258,12 @@
    * @param suffixDn the DN of the suffix to be analyzed.
    * @return <CODE>true</CODE> if the provided String is the DN of a suffix
    * and <CODE>false</CODE> otherwise.
+   * @throws IllegalArgumentException if a node with the given dn exists but
+   * is not a suffix node.
    */
-  public boolean hasSuffix(String suffixDn) {
+  public boolean hasSuffix(String suffixDn)
+  throws IllegalArgumentException
+  {
     return (findSuffixNode(suffixDn, rootNode) != null);
   }
 
@@ -270,8 +274,11 @@
    * @param parentSuffixDn the DN of the parent suffix (or <CODE>null</CODE> if
    * there is no parent DN).
    * @return the TreePath of the new node.
+   * @throws IllegalArgumentException if a node with the given dn exists.
    */
-  public TreePath addSuffix(String suffixDn, String parentSuffixDn) {
+  public TreePath addSuffix(String suffixDn, String parentSuffixDn)
+  throws IllegalArgumentException
+  {
     SuffixNode parentNode;
     if (parentSuffixDn != null) {
       parentNode = findSuffixNode(parentSuffixDn, rootNode);
@@ -1926,8 +1933,12 @@
    * @param suffixNode the node from which we start searching.
    * @return the SuffixNode associated with the provided DN.  <CODE>null</CODE>
    * if nothing is found.
+   * @throws IllegalArgumentException if a node with the given dn exists but
+   * is not a suffix node.
    */
-  SuffixNode findSuffixNode(String suffixDn, SuffixNode suffixNode) {
+  SuffixNode findSuffixNode(String suffixDn, SuffixNode suffixNode)
+  throws IllegalArgumentException
+  {
     SuffixNode result;
 
     if (Utilities.areDnsEqual(suffixNode.getDN(), suffixDn)) {
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java
index f8e39c4..baf3b9d 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java
@@ -664,6 +664,7 @@
     setPrimaryValid(lFilter);
     String s = getBaseDN();
     boolean displayAll = false;
+    DN theDN = null;
     if (s != null)
     {
       displayAll = s.equals(ALL_BASE_DNS);
@@ -671,7 +672,7 @@
       {
         try
         {
-          DN.decode(s);
+          theDN = DN.decode(s);
         }
         catch (Throwable t)
         {
@@ -712,6 +713,10 @@
         {
           for (BaseDNDescriptor baseDN : backend.getBaseDns())
           {
+            if ((theDN != null) && baseDN.getDn().equals(theDN))
+            {
+              isBaseDN = true;
+            }
             String dn = Utilities.unescapeUtf8(baseDN.getDn().toString());
             if (displayAll)
             {
@@ -720,7 +725,6 @@
             else if (s.equals(dn))
             {
               controller.addSuffix(dn, null);
-              isBaseDN = true;
             }
           }
         }
@@ -1331,16 +1335,22 @@
                 }
                 if (baseDN.getEntries() > 0)
                 {
-                  if (!controller.hasSuffix(dn))
+                  try
                   {
-                    if (displayAll)
+                    if (!controller.hasSuffix(dn))
                     {
-                      controller.addSuffix(dn, null);
+                      if (displayAll || isBaseDN)
+                      {
+                        controller.addSuffix(dn, null);
+                      }
                     }
-                    else if (s.equals(dn))
-                    {
-                      controller.addSuffix(dn, null);
-                    }
+                  }
+                  catch (IllegalArgumentException iae)
+                  {
+                    // The suffix node exists but is not a suffix node.
+                    // Simply log a message.
+                    LOG.log(Level.WARNING, "Suffix: "+dn+
+                        " added as a non suffix node. Exception: "+iae, iae);
                   }
                 }
               }

--
Gitblit v1.10.0