From 767097d8baff57920038ea1f6e2e772d6612ea0c Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Thu, 29 Mar 2007 22:39:31 +0000
Subject: [PATCH] Fix for issue 1409 (uncatch exceptions during setup if not enough swap space).

---
 opends/src/quicksetup/org/opends/quicksetup/util/Utils.java |   42 ++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java b/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
index 5b794c4..ca80024 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
@@ -722,12 +722,21 @@
       msg = i18n.getMsg(key);
     }
 
+    String tag;
+    if (isOutOfMemory(t))
+    {
+      tag = "exception-out-of-memory-details";
+    }
+    else
+    {
+      tag = "exception-details";
+    }
     String detail = t.toString();
     if (detail != null)
     {
       String[] arg =
-        { detail };
-      msg = msg + "  " + i18n.getMsg("exception-details", arg);
+      { detail };
+      msg = msg + "  " + i18n.getMsg(tag, arg);
     }
     return msg;
   }
@@ -1438,4 +1447,33 @@
     System.setProperty("com.apple.mrj.application.apple.menu.about.name",
                        appName);
   }
+
+  /**
+    * Tells whether this throwable has been generated for an out of memory
+    * error or not.
+    * @param t the throwable to analyze.
+    * @return <CODE>true</CODE> if the throwable was generated by an out of
+    * memory error and false otherwise.
+    */
+  private static boolean isOutOfMemory(Throwable t)
+  {
+    boolean isOutOfMemory = false;
+    while (!isOutOfMemory && (t != null))
+    {
+      if (t instanceof OutOfMemoryError)
+      {
+        isOutOfMemory = true;
+      }
+      else if (t instanceof IOException)
+      {
+        String msg = t.toString();
+        if (msg != null)
+        {
+          isOutOfMemory = msg.indexOf("Not enough space") != -1;
+        }
+      }
+      t = t.getCause();
+    }
+    return isOutOfMemory;
+  }
 }

--
Gitblit v1.10.0