0
votes

I have a instance of HashMap<MyClass2,Queue<Point2D>> in my class. My class implements JPanel. Findbugs is showing SE_BAD_FIELD for the instance of HashMap in my class but HashMap implements Serializable. I am using findbugs 3.0.0X, and JDK 1.7.0_45.

Se: Non-transient non-serializable instance field in serializable class (SE_BAD_FIELD)

This Serializable class defines a non-primitive instance field which is neither transient, Serializable, or java.lang.Object, and does not appear to implement the Externalizable interface or the readObject() and writeObject() methods. Objects of this class will not be deserialized correctly if a non-Serializable object is stored in this field.


1
Is every field in MyClass2 serializable? What about Point2D?WPrecht
Key type and Value type of HashMap should be Serializable too?वरुण
MyClass2 is not Serializable. Point2D is a java class from java.awt.geom package.वरुण
If MyClass2 is not Serializable, a HashMap with them as the Key Type won't be either, so that's the problem.WPrecht

1 Answers

0
votes

If you define a HashMap field as:

private Map<MyClass2,Queue<Point2D>> map = new HashMap<>();

FindBugs will complain because Map interface is not serializable, so you can put any class there that might not be serializable, if you change the type to HashMap (or add transient) you will get rid of the warning.