Java 使用实用程序静态方法的类给出了非暂时的不可序列化实例字段错误

Java 使用实用程序静态方法的类给出了非暂时的不可序列化实例字段错误,java,findbugs,Java,Findbugs,我有一个只使用静态方法的实用程序类 public final class ABC { /** * private constructor to prevent from object creation */ private ABC() { } private static Map<String, String> buildInfo(@NonNull final X x) { final DataClass da

我有一个只使用静态方法的实用程序类

public final class ABC {

    /**
     * private constructor to prevent from object creation
     */
    private ABC() {
    }

    private static Map<String, String> buildInfo(@NonNull final X x) {

        final DataClass dataClass = x.getData();

        /**
          Some manipulation
        **/
        return info;
    }
}


为什么在我不尝试使事物可序列化的实用程序方法中出现此错误?

这是因为我返回了

 Map<String, Integer> info = new HashMap<String, Integer>() {{
            put(Constants.ID_KEY, dataClass.getId());
            put(Constants.NAME_KEY, dataClass.getName());
        }};
Map info=newhashmap(){{
put(Constants.ID_KEY,dataClass.getId());
put(Constants.NAME_KEY,dataClass.getName());
}};
创建匿名类

创建一个类,该类是HashMap的子类,其中HashMap是可序列化的,而这个新的子类是不可序列化的


基本上,只需使用Immutable Map Builder或HashMap手动添加每一行,而不是创建匿名子类

这里唯一的
Serializable
类是
String
。不清楚您在问什么。@user207421,当我编写这个实用程序方法时,它给出了SE_BAD_字段警告,在这里我根本看不到这个警告的任何原因,因为我没有试图序列化实用程序类中的任何内容。让我知道这有助于理解问题是什么。
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.
 Map<String, Integer> info = new HashMap<String, Integer>() {{
            put(Constants.ID_KEY, dataClass.getId());
            put(Constants.NAME_KEY, dataClass.getName());
        }};