Re: Java heap space

Stefaan A Eeckels <[email protected]> Fri, 15 Sep 2006 12:20:44 +0200
Newsgroups gmane.comp.db.mckoi
Organization E.C.C. sa - Computer Consultants
Message-ID <[email protected]>
On Thu, 14 Sep 2006 21:07:48 +0200
Stefaan A Eeckels <[email protected]> wrote:

> OK, I can reproduce this. I'd have to look in the source code to see
> what causes the out of memory error.

I've found (and fixed) the problem. Two messages with attachments have
failed to materialize on the list, which might be caused by the
attachments. Hence this message, with the patch as a text attachment.

Here's the text from the previous messages:

> It's a bug in the code - the  'E\\_%' pattern causes an endless
> loop in PatternSearch.search. I have a fix for this that -after
> cursory testing- seems to work. 
> 
> I attach a patch with the fix as well as a fix for the compilation
> with Java 5 (McKoi used "enum" as a variable name, in Java 5 it's a
> reserved word).
> 
> Mckoi with the attached patch and compiled with Java 1.5.008 is
> running quite nicely.


-- 
Stefaan
-- 
As complexity rises, precise statements lose meaning,
and meaningful statements lose precision. -- Lotfi Zadeh


---------------------------------------------------------------
Mckoi SQL Database mailing list  http://www.mckoi.com/database/
To unsubscribe, send a message to [email protected]
wildcard_java5.patch (text/plain, 8.6 KB)
diff -urw mckoi1.0.3/src/com/mckoi/database/FunctionTable.java mckoi1.0.3.sae//src/com/mckoi/database/FunctionTable.java
--- mckoi1.0.3/src/com/mckoi/database/FunctionTable.java	Tue Apr  8 01:55:02 2003
+++ mckoi1.0.3.sae//src/com/mckoi/database/FunctionTable.java	Thu Sep 14 22:58:37 2006
@@ -239,12 +239,12 @@
 
     // Set up 'whole_table_group' to the list of all rows in the reference
     // table.
-    RowEnumeration enum = getReferenceTable().rowEnumeration();
-    whole_table_is_simple_enum = enum instanceof SimpleRowEnumeration;
+    RowEnumeration theEnum = getReferenceTable().rowEnumeration();
+    whole_table_is_simple_enum = theEnum instanceof SimpleRowEnumeration;
     if (!whole_table_is_simple_enum) {
       whole_table_group = new IntegerVector(getReferenceTable().getRowCount());
-      while (enum.hasMoreRows()) {
-        whole_table_group.addInt(enum.nextRowIndex());
+      while (theEnum.hasMoreRows()) {
+        whole_table_group.addInt(theEnum.nextRowIndex());
       }
     }
 
@@ -425,9 +425,9 @@
       // This means there is no grouping, so merge with entire table,
       int r_count = table.getRowCount();
       row_list = new IntegerVector(r_count);
-      RowEnumeration enum = table.rowEnumeration();
-      while (enum.hasMoreRows()) {
-        row_list.addInt(enum.nextRowIndex());
+      RowEnumeration theEnum = table.rowEnumeration();
+      while (theEnum.hasMoreRows()) {
+        row_list.addInt(theEnum.nextRowIndex());
       }
     }
 
diff -urw mckoi1.0.3/src/com/mckoi/database/NaturallyJoinedTable.java mckoi1.0.3.sae//src/com/mckoi/database/NaturallyJoinedTable.java
--- mckoi1.0.3/src/com/mckoi/database/NaturallyJoinedTable.java	Sat Sep 21 21:37:06 2002
+++ mckoi1.0.3.sae//src/com/mckoi/database/NaturallyJoinedTable.java	Thu Sep 14 22:58:50 2006
@@ -86,9 +86,9 @@
    */
   private static IntegerVector createLookupRowList(Table t) {
     IntegerVector ivec = new IntegerVector();
-    RowEnumeration enum = t.rowEnumeration();
-    while (enum.hasMoreRows()) {
-      int row_index = enum.nextRowIndex();
+    RowEnumeration theEnum = t.rowEnumeration();
+    while (theEnum.hasMoreRows()) {
+      int row_index = theEnum.nextRowIndex();
       ivec.addInt(row_index);
     }
     return ivec;
diff -urw mckoi1.0.3/src/com/mckoi/database/PatternSearch.java mckoi1.0.3.sae//src/com/mckoi/database/PatternSearch.java
--- mckoi1.0.3/src/com/mckoi/database/PatternSearch.java	Mon Feb  3 13:42:58 2003
+++ mckoi1.0.3.sae//src/com/mckoi/database/PatternSearch.java	Fri Sep 15 10:17:34 2006
@@ -204,7 +204,6 @@
 
     // Look at first character in pattern, if it's a ONE_CHAR wildcard then
     // check expression and pattern match until next wild card.
-
     if (pattern.charAt(0) == ONE_CHAR) {
 
       // Else step through each character in pattern and see if it matches up
@@ -382,6 +381,7 @@
 
     StringBuffer pre_pattern = new StringBuffer();
     int i = 0;
+    int j = 0;
     boolean finished = i >= pattern.length();
     boolean last_is_escape = false;
 
@@ -388,14 +388,24 @@
     while (!finished) {
       char c = pattern.charAt(i);
       if (last_is_escape) {
-        last_is_escape = true;
+        last_is_escape = false;
         pre_pattern.append(c);
+        j++;
+        ++i;
+        if (i >= pattern.length()) {
+          finished = true;
       }
+      }
       else if (c == escape_char) {
         last_is_escape = true;
+        ++i;
+        if (i >= pattern.length()) {
+          finished = true;
       }
+      }
       else if (!isWildCard(c)) {
         pre_pattern.append(c);
+        j++;
 
         ++i;
         if (i >= pattern.length()) {
@@ -446,8 +456,8 @@
       // 'Geoff\33'
 
       String lower_bounds = new String(pre_pattern);
-      int next_char = pre_pattern.charAt(i - 1) + 1;
-      pre_pattern.setCharAt(i - 1, (char) next_char);
+      int next_char = pre_pattern.charAt(j - 1) + 1;
+      pre_pattern.setCharAt(j - 1, (char) next_char);
       String upper_bounds = new String(pre_pattern);
 
       post_pattern = pattern.substring(i);
diff -urw mckoi1.0.3/src/com/mckoi/database/Table.java mckoi1.0.3.sae//src/com/mckoi/database/Table.java
--- mckoi1.0.3/src/com/mckoi/database/Table.java	Tue Mar  4 16:11:40 2003
+++ mckoi1.0.3.sae//src/com/mckoi/database/Table.java	Fri Sep 15 01:29:08 2006
@@ -1597,9 +1597,9 @@
    */
   public final IntegerVector selectAll() {
     IntegerVector list = new IntegerVector(getRowCount());
-    RowEnumeration enum = rowEnumeration();
-    while (enum.hasMoreRows()) {
-      list.addInt(enum.nextRowIndex());
+    RowEnumeration theEnum = rowEnumeration();
+    while (theEnum.hasMoreRows()) {
+      list.addInt(theEnum.nextRowIndex());
     }
     return list;
   }
@@ -1751,9 +1751,9 @@
   public Map toMap() {
     if (getColumnCount() == 2) {
       HashMap map = new HashMap();
-      RowEnumeration enum = rowEnumeration();
-      while (enum.hasMoreRows()) {
-        int row_index = enum.nextRowIndex();
+      RowEnumeration theEnum = rowEnumeration();
+      while (theEnum.hasMoreRows()) {
+        int row_index = theEnum.nextRowIndex();
         TObject key = getCellContents(0, row_index);
         TObject value = getCellContents(1, row_index);
         map.put(key.getObject().toString(), value.getObject());
diff -urw mckoi1.0.3/src/com/mckoi/database/control/DefaultDBConfig.java mckoi1.0.3.sae//src/com/mckoi/database/control/DefaultDBConfig.java
--- mckoi1.0.3/src/com/mckoi/database/control/DefaultDBConfig.java	Tue Jul 23 00:31:36 2002
+++ mckoi1.0.3.sae//src/com/mckoi/database/control/DefaultDBConfig.java	Thu Sep 14 22:55:47 2006
@@ -93,10 +93,10 @@
     Properties config = new Properties();
     config.load(new BufferedInputStream(input));
     // For each property in the file
-    Enumeration enum = config.propertyNames();
-    while (enum.hasMoreElements()) {
+    Enumeration theEnum = config.propertyNames();
+    while (theEnum.hasMoreElements()) {
       // Set the property value in this configuration.
-      String property_key = (String) enum.nextElement();
+      String property_key = (String) theEnum.nextElement();
       setValue(property_key, config.getProperty(property_key));
     }
   }
diff -urw mckoi1.0.3/src/com/mckoi/database/interpret/Insert.java mckoi1.0.3.sae//src/com/mckoi/database/interpret/Insert.java
--- mckoi1.0.3/src/com/mckoi/database/interpret/Insert.java	Tue Jul 22 01:54:32 2003
+++ mckoi1.0.3.sae//src/com/mckoi/database/interpret/Insert.java	Thu Sep 14 22:55:41 2006
@@ -274,9 +274,9 @@
       // Copy row list into an intermediate IntegerVector list.
       // (A RowEnumeration for a table being modified is undefined).
       IntegerVector row_list = new IntegerVector();
-      RowEnumeration enum = result.rowEnumeration();
-      while (enum.hasMoreRows()) {
-        row_list.addInt(enum.nextRowIndex());
+      RowEnumeration theEnum = result.rowEnumeration();
+      while (theEnum.hasMoreRows()) {
+        row_list.addInt(theEnum.nextRowIndex());
       }
 
       // For each row of the select table.
diff -urw mckoi1.0.3/src/com/mckoi/database/jdbcserver/AbstractJDBCDatabaseInterface.java mckoi1.0.3.sae//src/com/mckoi/database/jdbcserver/AbstractJDBCDatabaseInterface.java
--- mckoi1.0.3/src/com/mckoi/database/jdbcserver/AbstractJDBCDatabaseInterface.java	Tue Apr  8 02:36:06 2003
+++ mckoi1.0.3.sae//src/com/mckoi/database/jdbcserver/AbstractJDBCDatabaseInterface.java	Fri Sep 15 10:16:07 2006
@@ -770,9 +770,9 @@
       // Build 'row_index_map' if not a simple enum
       if (!result_is_simple_enum) {
         row_index_map = new IntegerVector(table.getRowCount());
-        RowEnumeration enum = table.rowEnumeration();
-        while (enum.hasMoreRows()) {
-          row_index_map.addInt(enum.nextRowIndex());
+        RowEnumeration theEnum = table.rowEnumeration();
+        while (theEnum.hasMoreRows()) {
+          row_index_map.addInt(theEnum.nextRowIndex());
         }
       }
 
diff -urw mckoi1.0.3/src/com/mckoi/database/sql/SQL.java mckoi1.0.3.sae//src/com/mckoi/database/sql/SQL.java
--- mckoi1.0.3/src/com/mckoi/database/sql/SQL.java	Tue Jul  6 17:14:22 2004
+++ mckoi1.0.3.sae//src/com/mckoi/database/sql/SQL.java	Thu Sep 14 22:59:36 2006
@@ -5998,8 +5998,8 @@
         jj_expentry[i] = jj_lasttokens[i];
       }
       boolean exists = false;
-      for (java.util.Enumeration enum = jj_expentries.elements(); enum.hasMoreElements();) {
-        int[] oldentry = (int[])(enum.nextElement());
+      for (java.util.Enumeration theEnum = jj_expentries.elements(); theEnum.hasMoreElements();) {
+        int[] oldentry = (int[])(theEnum.nextElement());
         if (oldentry.length == jj_expentry.length) {
           exists = true;
           for (int i = 0; i < jj_expentry.length; i++) {