Hello,
We have noticed that your code goes into a never
ending loop when trying to parse a file containing
empty lines.
Indeed, your code from the LineFormat class is the
following one :
public String[] parse(String s, boolean
autoTrim) throws FFPParseException {
// Locate the line separators and
split into physical lines without
// separators
List l = new ArrayList();
int i, currIndex = 0;
do {
i = s.indexOf(lineSeparator,
currIndex);
// i==-1 at the last line
CharSequence line =
s.subSequence
(currIndex, (i == -1) ? s.length() : i);
if (line.length() > 0) {
l.add(line);
currIndex = i +
lineSeparator.length();
}
} while (i != -1);
If the s string is "\r\n", then, at the first run of
the loop, the value of i will be 0, the value of line
will be "" and as long as the line is empty, the
value of the current index called currIndex will
never change and, at the second run of the loop, the
value of i will still be 0 ... => never ending loop !
I suggest the following code :
public String[] parse(String s, boolean
autoTrim) throws FFPParseException {
// Locate the line separators and
split into physical lines without
// separators
List l = new ArrayList();
int i, currIndex = 0;
do {
i = s.indexOf(lineSeparator,
currIndex);
// i==-1 at the last line
CharSequence line =
s.subSequence
(currIndex, (i == -1) ? s.length() : i);
if (line.length() > 0) {
l.add(line);
} else if(l.isEmpty()) { //
line.length() is equal to 0 => register an empty line
if there is one really
l.add(line);
}
currIndex = i +
lineSeparator.length();
} while (i != -1);
Please let me know what you think about my solution.
Thanks
Alexandre Duvallet
Logged In: NO
This problem still exists in 1.2?