[
https://issues.apache.org/jira/browse/MATH-198?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Luc Maisonobe resolved MATH-198.
--------------------------------
Resolution: Fixed
Fixed in svn as of r 640191.
The adopted fixed is different from the proposed one, it simply checks the
length of the string with respect to the expected position of the imaginary
character
> java.lang.StringIndexOutOfBoundsException in ComplexFormat.parse(String
> source, ParsePosition pos)
> --------------------------------------------------------------------------------------------------
>
> Key: MATH-198
> URL: https://issues.apache.org/jira/browse/MATH-198
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: 1.2
> Environment: Ubuntu 7.10, JDK 6.0, PC
> Reporter: Frederick Salardi
>
> The parse(String source, ParsePosition pos) method in the ComplexFormat class
> does not check whether the imaginary character is set or not which produces
> StringIndexOutOfBoundsException in the substring method :
> (line 375 of ComplexFormat)
> ...
> // parse imaginary character
> int n = getImaginaryCharacter().length();
>
> startIndex = pos.getIndex();
> int endIndex = startIndex + n;
> if (source.substring(startIndex, endIndex).compareTo(
> getImaginaryCharacter()) != 0) {
> ...
> I encoutered this exception typing in a JTextFied with ComplexFormat set to
> look up an AbstractFormatter.
> If only the user types the imaginary part of the complex number first, he
> gets this exception.
> Solution: Before setting to n length of the imaginary character, check if the
> source contains it. My proposal:
> ...
> int n = 0;
> if (source.contains(getImaginaryCharacter()))
> n = getImaginaryCharacter().length();
> ...
> F.S.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.