A bug in the JAVA7 environment where the spring container deserializes the locale object.

Source: Internet
Author: User
Tags getscript


When you deserialize an object in spring, you need to call the Readresolve method to verify the integrity of the object. For JAVA6 locale objects, the specific implementation

Private Object Readresolve () throws Java.io.ObjectStreamException {        return getinstance (language, country, variant) ;}

No problem. But for JAVA7, the real

Private Object Readresolve () throws Java.io.ObjectStreamException {           return getinstance (Baselocale.getlanguage (), Baselocale.getscript (),                  baselocale.getregion (), Baselocale.getvariant (), localeextensions);}

We know that the locale object that calls the Readresolve method is the Hessian implementation in the spring framework, is generated directly in memory using the Sun.misc.UnSafe Allocateinstance method, and then via ReadObject (Abstracthessianinput in, Object obj,string[] FieldNames) assigns a value to the field of this object and does not construct by invoking the new method of the object, which is not constructed by the Java general construction method. So here's the problem.

In Java7, the Baselocale field of the locale is a transient field that is not serialized and is dynamically constructed in the object construction method based on several other fields.

Public Locale (String language, String country, string variant) {            if (language== null | | country = = NULL | | variant = = NULL) {               throw new NullPointerException ();            }            Baselocale = Baselocale.getinstance (convertoldisocodes (language), "", country, variant);            Localeextensions = getcompatibilityextensions (Language, "", country, variant);}


So, with the implementation of spring above, the Baselocale field of the locale object calling the Readresolve object cannot be initialized, only null, so

Return getinstance (Baselocale.getlanguage (), Baselocale.getscript (),                  baselocale.getregion (), Baselocale.getvariant (), localeextensions);
The null pointer exception must be thrown here.



A bug in the JAVA7 environment where the spring container deserializes the locale object.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.