Name: gm110360 Date: 03/13/2002
FULL PRODUCT VERSION :
java version "1.4.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91)
Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
Using the value of the "line.separator" system property to
separate lines when appending to a TextArea causes the lines
to get all jumbled with the Java 1.4 appletviewer and with
the Java 1.4 Plug-in. The problem does not occur when using
the appletviewer of Java 1.0.2, Java 1.1.8_008, Java
1.2.2_010, nor Java 1.3.1_02-b02.
REGRESSION. Last worked in version 1.3.1
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the sample program below using the appletviewer.
2. Enter multiple lines of text into the text field, each
followed by the Enter key.
3. Look at the corresponding lines in the text area.
EXPECTED VERSUS ACTUAL BEHAVIOR :
If you typed:
line1
line2
line3
you should see the following in the text area:
line1
line2
line3
With Java 1.4, you instead see:
lin
lin
line3e2e1
Note that the first line printed in the text area is the hex
value of the "line.separator" system property.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
None.
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
HTML for appletviewer:
----------------------
<html>
<head>
<title>TextArea Test</title>
</head>
<body>
<h1>TextArea Test</h1>
<applet code="Append.class" width="300" height="300">
</applet>
</body>
</html>
Java 1.0.2 source code:
-----------------------
import java.applet.*;
import java.awt.*;
public class Append extends Applet {
private static final String LINE_SEPARATOR =
System.getProperty("line.separator", "\n");
private static final char[] DIGITS =
{'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
private static final Font FONT = new Font("Courier", Font.PLAIN, 13);
private static final int NEW_LINE = '\n';
private static final int RETURN = '\r';
private static final int ESCAPE_KEY = 27;
private TextArea area;
private TextField field;
private static String hexEncode(byte[] bytes) {
StringBuffer buffer = new StringBuffer(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
byte b = bytes[i];
buffer.append(DIGITS[(b & 0xF0) >> 4]);
buffer.append(DIGITS[b & 0x0F]);
}
return buffer.toString();
}
public void init() {
area = new TextArea();
field = new TextField();
area.setFont(FONT);
field.setFont(FONT);
setLayout(new BorderLayout());
add("Center", area);
add("South", field);
byte[] bytes = new byte[LINE_SEPARATOR.length()];
LINE_SEPARATOR.getBytes(0, bytes.length, bytes, 0);
area.appendText(hexEncode(bytes));
}
public void start() {
field.requestFocus();
}
public boolean keyDown(Event event, int key) {
boolean handled = false;
if (event.target == field) {
String text = field.getText();
switch (key) {
case NEW_LINE: case RETURN:
// area.appendText("\n" + text);
area.appendText(LINE_SEPARATOR + text);
field.setText("");
handled = true;
break;
case ESCAPE_KEY:
field.setText("");
handled = true;
break;
}
}
return handled;
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
Use "\n" for the line separator character, regardless of the
platform.
(Review ID: 139621)
======================================================================