JDK-7152690 : Initialization error with charset SJIS_0213 when security manager is enabled
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio.charsets
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86
  • Submitted: 2012-03-09
  • Updated: 2012-07-12
  • Resolved: 2012-07-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u6 b17Fixed 8Fixed
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"));
04-04-2012