You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2008/03/23 13:23:07 UTC

svn commit: r640191 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/complex/ComplexFormat.java site/xdoc/changes.xml test/org/apache/commons/math/complex/ComplexFormatAbstractTest.java

Author: luc
Date: Sun Mar 23 05:22:59 2008
New Revision: 640191

URL: http://svn.apache.org/viewvc?rev=640191&view=rev
Log:
added an error detection for missing imaginary character while parsing complex string
JIRA: MATH-198

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/complex/ComplexFormat.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    commons/proper/math/trunk/src/test/org/apache/commons/math/complex/ComplexFormatAbstractTest.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/complex/ComplexFormat.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/complex/ComplexFormat.java?rev=640191&r1=640190&r2=640191&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/complex/ComplexFormat.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/complex/ComplexFormat.java Sun Mar 23 05:22:59 2008
@@ -374,7 +374,9 @@
         int n = getImaginaryCharacter().length();
         startIndex = pos.getIndex();
         int endIndex = startIndex + n;
-        if (source.substring(startIndex, endIndex).compareTo(
+        if ((startIndex >= source.length()) ||
+            (endIndex > source.length()) ||
+            source.substring(startIndex, endIndex).compareTo(
             getImaginaryCharacter()) != 0) {
             // set index back to initial, error index should be the start index
             // character examined.

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=640191&r1=640190&r2=640191&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Sun Mar 23 05:22:59 2008
@@ -44,6 +44,9 @@
       <action dev="brentworden" type="fix" issue="MATH-193" due-to="Michael Heuer and Sebb">
         Javadoc and style fixes.
       </action>
+      <action dev="luc" type="fix" issue="MATH-198" due-to="Frederick Salardi">
+        added an error detection for missing imaginary character while parsing complex string
+      </action>
     </release>
     <release version="1.2" date="2008-02-24"
     description="This release combines bug fixes and new features. Most notable

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/complex/ComplexFormatAbstractTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/complex/ComplexFormatAbstractTest.java?rev=640191&r1=640190&r2=640191&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/complex/ComplexFormatAbstractTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/complex/ComplexFormatAbstractTest.java Sun Mar 23 05:22:59 2008
@@ -19,6 +19,7 @@
 
 import java.text.NumberFormat;
 import java.text.ParseException;
+import java.text.ParsePosition;
 import java.util.Locale;
 
 import junit.framework.TestCase;
@@ -347,5 +348,11 @@
         } catch (IllegalArgumentException ex) {
             // success
         }
+    }
+
+    public void testForgottenImaginaryCharacter() {
+        ParsePosition pos = new ParsePosition(0);
+        assertNull(new ComplexFormat().parse("1 + 1", pos));
+        assertEquals(5, pos.getErrorIndex());
     }
 }