IBM JDK 不兼容 Sun JDK 备忘录

工作中遇到一些Sun JDK与IBM JDK不兼容的问题,记下来做个备忘

1. String.getBytes(String encoding)

TestCase:
 
    public static void main(String[] args) {
        try {
            RandomAccessFile f = new RandomAccessFile("test.txt", "rw");
            f.write("tets".getBytes(null));
            f.close();
        } catch (IOException e) {
            e.printStackTrace();           
        }
   }
 
SUN JDK 1.4 : OK

IBM JDK 1.4 :

Exception in thread "main" java.lang.NullPointerException
        at java.lang.StringCoding$EncoderCache.makeEncoder(StringCoding.java:198)
        at java.lang.StringCoding$2.run(StringCoding.java:251)
        at java.security.AccessController.doPrivileged1(Native Method)
        at java.security.AccessController.doPrivileged(AccessController.java:351)
        at java.lang.StringCoding$EncoderCache.getEncoder(StringCoding.java:248)
        at java.lang.StringCoding.getEncoder(StringCoding.java:331)
        at java.lang.StringCoding.encode(StringCoding.java:472)
        at java.lang.String.getBytes(String.java:947)
        at NullEncoding.main(NullEncoding.java:12)

 
 

2. 日文编码

Test Case:
 
    public static void main(String[] args) {
        try {
            "".getBytes("Shift_JIS");
            "".getBytes("Shift-JIS");
        } catch (Exception e) {
            e.printStackTrace();
        }
     }
 

SUN JDK 1.4 : OK

IBM JDK 1.4 :

java.io.UnsupportedEncodingException: Shift-JIS
        at java.lang.StringCoding$EncoderCache.getEncoder(StringCoding.java:262)
        at java.lang.StringCoding.getEncoder(StringCoding.java:331)
        at java.lang.StringCoding.encode(StringCoding.java:472)
        at java.lang.String.getBytes(String.java:947)
        at ShiftEncoding.main(ShiftEncoding.java:17)

 

To Be Continue...

你可能感兴趣的:(IBM JDK 不兼容 Sun JDK 备忘录)