The cause of java.io.InvalidClassException anomaly and its solution __serializab

Source: Internet
Author: User
First, the scene of abnormal occurrence

When you use Netty to do an Android message push, the following exception occurs:

Io.netty.handler.codec.DecoderException:java.io.InvalidClassException:failed to read class descriptor

Obviously, it's a coding-decoding anomaly. second, the cause of the anomaly

In the entire push project, the message is a class of messages that must be converted to byte transmission, so the serializable interface is implemented in the word class, and decoding is transmitted to the client in the server, which is where the error occurs. This is because the message class on the server side is different from the package path of the client's message class, causing the encoding and decoding to be inconsistent and will naturally report an exception. third, the class of exception-solving serialization is best combined with serialversionuid, Without java.io.InvalidClassException, different JVMs may not be able to compute the SERIALVERSIONUID, even if the definition of the class is consistent with the serialized object, and after the serialized object in Jvm-a is reached Jvm-b, Jvm-b believes Class Invalid The path of the server and client-side codec to be consistent

Related Article

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.