Hi All,

Thank you all for this wonderfull product called Castor :). I really like how 
it works, but I have found that on error when manipulating collections can be 
hard to trace.
Currently the generated code for collections just throws an 
IndexOutOfBoundsException when the item added to the collection does not fit 
the boundaries (max value) specified by the xsd (or castor code).

The patch I have attached should solve that problem. At least it does for 
me :)

Maybe more people are interested?

Thanks,
Roy van der Kuil
Index: src/main/org/exolab/castor/builder/CollectionInfo.java
===================================================================
RCS file: /cvs/castor/castor/src/main/org/exolab/castor/builder/CollectionInfo.java,v
retrieving revision 1.3
diff -u -3 -p -b -r1.3 CollectionInfo.java
--- a/src/main/org/exolab/castor/builder/CollectionInfo.java	26 Jun 2004 06:51:14 -0000	1.3
+++ b/src/main/org/exolab/castor/builder/CollectionInfo.java	1 Sep 2004 11:27:03 -0000
@@ -363,7 +363,7 @@ public class CollectionInfo extends Fiel
             jsc.append(Integer.toString(maxSize));
             jsc.append(")) {");
             jsc.indent();
-            jsc.add("throw new IndexOutOfBoundsException();");
+            jsc.add("throw new IndexOutOfBoundsException(\""+method.getName() +" has a maximum of "+maxSize+"\");");
             jsc.unindent();
             jsc.add("}");
         }
@@ -396,7 +396,7 @@ public class CollectionInfo extends Fiel
             jsc.append(Integer.toString(maxSize));
             jsc.append(")) {");
             jsc.indent();
-            jsc.add("throw new IndexOutOfBoundsException();");
+            jsc.add("throw new IndexOutOfBoundsException(\""+method.getName() +" has a maximum of "+maxSize+"\");");
             jsc.unindent();
             jsc.add("}");
         }
@@ -505,7 +505,7 @@ public class CollectionInfo extends Fiel
         jsc.append(getName());
         jsc.append(".size())) {");
         jsc.indent();
-        jsc.add("throw new IndexOutOfBoundsException();");
+        jsc.add("throw new IndexOutOfBoundsException(\""+method.getName()+": Index: \"+index+\" not in range[0..\"+"+getName()+".size()+\"]\");");
         jsc.unindent();
         jsc.add("}");
 
@@ -581,7 +581,7 @@ public class CollectionInfo extends Fiel
         jsc.append(getName());
         jsc.append(".size())) {");
         jsc.indent();
-        jsc.add("throw new IndexOutOfBoundsException();");
+        jsc.add("throw new IndexOutOfBoundsException(\""+method.getName()+": Index: \"+index+\" not in range[0..\"+"+getName()+".size()+\"]\");");
         jsc.unindent();
         jsc.add("}");
 
@@ -592,7 +592,7 @@ public class CollectionInfo extends Fiel
             jsc.append(Integer.toString(maxSize));
             jsc.append(")) {");
             jsc.indent();
-            jsc.add("throw new IndexOutOfBoundsException();");
+            jsc.add("throw new IndexOutOfBoundsException(\""+method.getName() +" has a maximum of "+maxSize+"\");");
             jsc.unindent();
             jsc.add("}");
         }
----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-user

Reply via email to