-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.4.0
-
x86
-
windows_2000
Name: nt126004 Date: 04/18/2002
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
Service Pack 2
A DESCRIPTION OF THE PROBLEM :
WHen I try to create strings in the default character
set, "Cp1252", I can't create strings for characters 128
through 159.
For example 153 which is, according to all sources I have
found, the trademark character in Cp1252. If I create a
byte array as {-103}, and create a string from it in the
default character set, the character returned is " And If
I specifically create a string in ISO-8859-1 with the TM
character, and I run str.getBytes(), the TM character is
converted to ?, which is byte value 63.
REGRESSION. Last worked in version 1.1.8
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.create a byte array as {-103}
2.create a string from it in the default character set
3.character returned is ", should be TM.
4.create a string in ISO-8859-1 with the TM character
5.call str.getBytes() to get a byte array
6.create a string from it in the default character set
7.byte's value is 63, should be -103
EXPECTED VERSUS ACTUAL BEHAVIOR :
The TM character was turned into a ? because java thought
cp1252 didn't have the TM character, and the byte value of -
103 was interpreted as the " charcter.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
no exceptions
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package cm.util;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class AsciiGet2 extends HttpServlet {
public void init(ServletConfig sc) throws ServletException {
super.init(sc);
}
protected void service(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title></title></head>");
out.println("<br><h1>IN CP1252 153=");
byte[] arr153 = { -103 };
String str153 = new String(arr153);
out.println(str153 + "</h1>");
out.println("<body><table border=1><tr><th>name</th><th>value</th>");
out.println
("<th>Byte</th><th>encoding</th><th>string</th><th>code</th></tr>");
for(int i = 1; i < 256; i++) {
if (request.getParameter("ascii0"+i) != null) {
out.println("<tr><td>ascii0" + i +"</td><td>"+
request.getParameter("ascii0"+i) +
"</td>");
byte[] b2 = (request.getParameter("ascii0"+i)).getBytes();
for (int j = 0; j < b2.length; j++) {
out.println("<td>"+b2[j]+"</td>");
}
String str = new String(b2);
byte[] b = str.getBytes();
InputStream inputStream = new ByteArrayInputStream(b);
InputStreamReader reader = new InputStreamReader(inputStream);
String defaultEncoding = reader.getEncoding();
reader.close();
out.println("<td>"+defaultEncoding+"</td>");
out.println("<td>"+str+"</td>");
for (int j = 0; j < b.length; j++) {
out.println("<td>"+b[j]+"</td>");
}
out.println("</tr>");
}
}
out.println("</table></body></html>");
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
no workaround
(Review ID: 144913)
======================================================================
- duplicates
-
JDK-4170549 Print{Stream,Writer} classes display characters incorrectly (win)
-
- Closed
-