United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7152690 Initialization error with charset SJIS_0213 when security manager is enabled
JDK-7152690 : Initialization error with charset SJIS_0213 when security manager is enabled

Details
Type:
Bug
Submit Date:
2012-03-09
Status:
Closed
Updated Date:
2012-07-12
Project Name:
JDK
Resolved Date:
2012-07-12
Component:
core-libs
OS:
windows_7
Sub-Component:
java.nio.charsets
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:
7u6 (b17)

Related Reports
Backport:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b05)
Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

EXTRA RELEVANT SYSTEM CONFIGURATION :
Java security manager is enabled.

-Djava.security.manager

A DESCRIPTION OF THE PROBLEM :
Charset "x-SJIS_0213" (or "SJIS_0213") fails in its initialization code and throws java.lang.ExceptionInInitializerError when Java security manager is enabled. It looks the implementation tries to load SJIS_0213.dat, but fails to open the resource.

This issue is not reproducible on

 - Java 6 or earlier releases
 - When security manager is disabled

REGRESSION.  Last worked in version 7


ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.ExceptionInInitializerError
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:264)
	at sun.nio.cs.AbstractCharsetProvider.lookup(AbstractCharsetProvider.java:142)
	at sun.nio.cs.AbstractCharsetProvider.charsetForName(AbstractCharsetProvider.java:161)
	at java.nio.charset.Charset.lookupExtendedCharset(Charset.java:462)
	at java.nio.charset.Charset.lookup2(Charset.java:487)
	at java.nio.charset.Charset.lookup(Charset.java:475)
	at java.nio.charset.Charset.forName(Charset.java:540)
	at com.ibm.icu.test.CharsetTest.test3(CharsetTest.java:34)
	at com.ibm.icu.test.CharsetTest.main(CharsetTest.java:11)
Caused by: java.lang.NullPointerException
	at sun.nio.cs.CharsetMapping.load(CharsetMapping.java:308)
	at sun.nio.cs.CharsetMapping$1.run(CharsetMapping.java:140)
	at sun.nio.cs.CharsetMapping$1.run(CharsetMapping.java:138)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.nio.cs.CharsetMapping.get(CharsetMapping.java:138)
	at sun.nio.cs.ext.SJIS_0213.<clinit>(SJIS_0213.java:76)
	... 10 more

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Example 1

byte[] data = {0x41, 0x42};
String s = new String(data, "x-SJIS_0213");

Example 2

Charset cs = Charset.forName("x-SJIS_0213");
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
For some reasons, if I insert a code -

SortedMap<String, Charset> availableCharset = Charset.availableCharsets();

before the code causing the issue, the problem is disappeared.

                                    

Comments
EVALUATION

The mapping init code in SJIS_2013 needs to put the "getResourceAsStream" part into  AccessController.doPrivileged block.

    static CharsetMapping mapping =
        CharsetMapping.get(SJIS_0213.class.getResourceAsStream("sjis0213.dat"));
                                     
2012-04-04



Hardware and Software, Engineered to Work Together