开发者

Java de-serialization of enums and valueOf

I've got a distributed system with a serializable enum class with constants that might vary across the system.

Because these classes may be different, valueOf could potentially be called upon deserialization on a constant that doesn't ex开发者_JS百科ist, throwing a runtime exception.

I don't believe valueOf can be overridden, or another method custom inserted before valueOf is called during deserialization.

Is there a way to avoid this problem with enums?


The main problem is the fact that you have enum with inconsistant content on your distributed system. The best thing to do is looking at this first.

A palliative would be to use a readObject() method in your sensitive classes and to catch exceptions dues to bad enum values.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜