This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
bug in PrettyWriter
- To: kawa at sources dot redhat dot com
- Subject: bug in PrettyWriter
- From: Felix S Klock II <pnkfelix at MIT dot EDU>
- Date: Fri, 17 Aug 2001 20:00:09 -0400
Kawa list-
There is a bug in the pretty printing routine; it does not properly
reset the prefix field when it discovers that the prefix needs to be
lengthened, due to the LHS of the assignment being bound to a local
variable and not the field that was desired.
Thus, when the array this.prefix[i] gets a new value in the code
immediately following this snippet, it throws
ArrayIndexOutOfBoundsException. A solution is to assign to
this.prefix instead of the local variable prefix.
However, I also fail to understand why the local variable prefix has
been introduced in the first place. It doesn't seem to serve any
purpose; perhaps it is legacy code. But I'll let Per explain his
thinking himself. All I know is that this seems to fix the (fairly
severe) problem for me.
I have not included a test case that exposes the bug, since generating
it requires a fairly deeply nested structure and I haven't figured out
a trivial way to generate such a structure for printing.
Index: gnu/text/PrettyWriter.java
===================================================================
RCS file: /cvs/kawa/kawa/gnu/text/PrettyWriter.java,v
retrieving revision 1.2
diff -u -r1.2 PrettyWriter.java
--- PrettyWriter.java 2001/07/17 19:28:54 1.2
+++ PrettyWriter.java 2001/08/17 23:46:29
@@ -385,7 +385,7 @@
{
char[] newPrefix = new char[enoughSpace(prefixLen, column -
prefixLen)];
System.arraycopy(prefix, 0, newPrefix, 0, current);
- prefix = newPrefix;
+ this.prefix = newPrefix;
}
if (column > current)
{