JDK-4369481 : file.encoding CP1252 improperly displays \u00b2 on Windows
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio.charsets
  • Affected Version: 1.3.0,1.3.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2000-09-08
  • Updated: 2006-02-01
  • Resolved: 2006-02-01
Related Reports
Duplicate :  
Duplicate :  
Description
Name: rl43681			Date: 09/08/2000


java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

Consider the following program:

import java.io.*;
public class Tmp {

    public static void main(String[] args){
        System.out.println(System.getProperty("file.encoding"));
        System.out.println('\u00b2');
    }
}

when run (from the Command Prompt, i.e. DOS window) it produces:

J:\borsotti\jtest>java Tmp
Cp1252
|

the character displayed on the second line is actually rendered as
a grey box with diagonal black lines in the DOS window.
This is what it should be cosidering that the file encoding that
is displayed on the first line of output is Cp1252, which is not
correct. I.e. java thinks that the underlying encoding is Cp1252
and encodes 00b2 (which is superscript 2) in it, outputting
a byte whose value is 0xb2. When that is sent to the window driver,
the driver interprets it as if it were a Cp437 character, and selects
the appropriate glyph, which is a grey box.
The problem is that when the java VM has been run from a DOS window,
it does not take into account that the encoding for the standard
output is NOT the default one for NT, and not even the one of DOS
(which should be the one defined in config.sys, that for my PC is
COUNTRY=039,850), but seems to be the standard default DOS one.
With this bug, instead of seeing a superscript 2, you see a grey box.
  To see the correct output there is a need to run the program in
this way:

J:\borsotti\jtest>java -Dfile.encoding=Cp437 Tmp
Cp437
2

This, however, is not a solution because it would affect all the
output, not only the one directed to the standard output.
(Review ID: 109421) 
======================================================================