[seam-commits] Seam SVN: r7421 - trunk/ui/src/main/java/org/jboss/seam/ui/validator.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu Feb 14 02:57:43 EST 2008


Author: christian.bauer at jboss.com
Date: 2008-02-14 02:57:43 -0500 (Thu, 14 Feb 2008)
New Revision: 7421

Modified:
   trunk/ui/src/main/java/org/jboss/seam/ui/validator/FormattedTextValidator.java
Log:
Avoid IOOBE when extracting ANTLR error message

Modified: trunk/ui/src/main/java/org/jboss/seam/ui/validator/FormattedTextValidator.java
===================================================================
--- trunk/ui/src/main/java/org/jboss/seam/ui/validator/FormattedTextValidator.java	2008-02-14 07:55:02 UTC (rev 7420)
+++ trunk/ui/src/main/java/org/jboss/seam/ui/validator/FormattedTextValidator.java	2008-02-14 07:57:43 UTC (rev 7421)
@@ -93,13 +93,15 @@
      */
     public static String getErrorMessage(String originalText,
             RecognitionException re) {
-        int beginIndex = Math.max(re.getColumn() - 1
-                - NUMBER_OF_CONTEXT_CHARS_BEFORE, 0);
-        int endIndex = Math.min(re.getColumn() + NUMBER_OF_CONTEXT_CHARS_AFTER,
-                originalText.length());
-        String msg = re.getMessage() + " at '" + (beginIndex == 0 ? "" : "...")
-                + originalText.substring(beginIndex, endIndex)
-                + (endIndex == originalText.length() ? "" : "...") + "'";
-        return msg.replace("\n", " ").replace("\r", " ").replace("\uFFFF","[END OF TEXT]").replace("#{", "# {");
+
+        // Avoid IOOBE even if what we show is wrong, we need to figure out why the indexes are off sometimes
+        int beginIndex = Math.max(re.getColumn() - 1 - NUMBER_OF_CONTEXT_CHARS_BEFORE, 0);
+        int endIndex = Math.min(re.getColumn() + NUMBER_OF_CONTEXT_CHARS_AFTER, originalText.length());
+        String snippet = originalText.length() > 50 ? originalText.substring(0, 50) : originalText;
+        if (beginIndex > 0 && beginIndex < endIndex && endIndex > 0 && endIndex < originalText.length())
+            snippet = "..." + originalText.substring(beginIndex, endIndex) + "...";
+
+        String msg = re.getMessage() + " at '" + snippet + "'";
+        return msg.replace("\n", " ").replace("\r", " ").replace("\uFFFF","END OF TEXT").replace("#{", "# {");
     }
 }




More information about the seam-commits mailing list