openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mprud...@apache.org
Subject svn commit: r487401 - /incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Substring.java
Date Fri, 15 Dec 2006 00:04:15 GMT
Author: mprudhom
Date: Thu Dec 14 16:04:14 2006
New Revision: 487401

URL: http://svn.apache.org/viewvc?view=rev&rev=487401
Log:
Prevent the end range of a substring from going over the end of the string.

Modified:
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Substring.java

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Substring.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Substring.java?view=diff&rev=487401&r1=487400&r2=487401
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Substring.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Substring.java
Thu Dec 14 16:04:14 2006
@@ -50,8 +50,10 @@
         Object arg = _args.eval(candidate, orig, ctx, params);
         if (arg instanceof Object[]) {
             Object[] args = (Object[]) arg;
-            return str.toString().substring(((Number) args[0]).intValue(),
-                ((Number) args[1]).intValue());
+            int start = ((Number) args[0]).intValue();
+            int end = Math.min(((Number) args[1]).intValue(),
+                str.toString().length() - start + 1);
+            return str.toString().substring(start, end);
         }
         return str.toString().substring(((Number) arg).intValue());
     }



Mime
View raw message