From 193ed3e5c3dcff19482599a070861da2c1fb5015 Mon Sep 17 00:00:00 2001
From: Ludovic Poitou <ludovic.poitou@forgerock.com>
Date: Thu, 10 Dec 2015 16:39:09 +0000
Subject: [PATCH] OPENDJ-2528 - Control Panel: Manage Entries > Right-click > Duplicate Entry throws NPE. Protect from the use of uninitialised rdnAttribute. Also prevent NPE when the duplicated entry has no parent (dc=com).

---
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/DuplicateEntryPanel.java |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/DuplicateEntryPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/DuplicateEntryPanel.java
index 6de2961..91e2b6a 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/DuplicateEntryPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/DuplicateEntryPanel.java
@@ -75,7 +75,6 @@
   private JLabel lconfirmPassword;
   private JPasswordField confirmPassword = Utilities.createPasswordField(25);
   private JLabel lPasswordInfo;
-  private JButton browse;
   private JLabel dn;
 
   private GenericDialog browseDlg;
@@ -152,7 +151,7 @@
       throw new IllegalStateException("Unexpected error decoding dn: '"+
           node.getDN()+"' error: "+de, de);
     }
-    parentDN.setText(aParentDN.toString());
+    parentDN.setText(aParentDN != null ? aParentDN.toString() : "");
     name.setText(aRdn);
     password.setText("");
     confirmPassword.setText("");
@@ -221,8 +220,8 @@
     gbc.gridx = 1;
     add(parentDN, gbc);
 
-    browse = Utilities.createButton(
-        INFO_CTRL_PANEL_BROWSE_BUTTON_LABEL.get());
+    JButton browse = Utilities.createButton(
+            INFO_CTRL_PANEL_BROWSE_BUTTON_LABEL.get());
     gbc.weightx = 0.0;
     gbc.gridx = 2;
     add(browse, gbc);
@@ -403,7 +402,7 @@
       }
       else
       {
-        String newValue = null;
+        String newValue;
         try
         {
           DN theDN = DN.valueOf(dn);
@@ -421,7 +420,7 @@
         }
         else
         {
-          String oldValue = null;
+          String oldValue;
           try
           {
             DN oldDN = DN.valueOf(entryToDuplicate.getDN());
@@ -535,7 +534,8 @@
   private void updateDNValue()
   {
     String value = name.getText().trim();
-    if (value.length() > 0)
+    // If it takes time to read the entry, the rdnAttribute might not be initialized yet. Don't try to use it then.
+    if (value.length() > 0 && rdnAttribute != null)
     {
        String rdn = Utilities.getRDNString(rdnAttribute, value);
           dn.setText(rdn+","+parentDN.getText().trim());

--
Gitblit v1.10.0