带有实用程序静态方法的类给出了非瞬态的不可序列化实例字段错误

问题描述 投票:0回答:1

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

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;
    }
}

X类的数据类带有

class X {
    DataClass dataClass;
    ...
};

class DataClass {
    ...
    Optional<String> abc;
    ...
}


这段代码给出“ FindBugs已报告警告”。 DataClass的SE_BAD_FIELD: Non-transient non-Serialization instance field in serializable class

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.

为什么它在实用程序方法中给此错误,而我不想使事情可序列化?

java findbugs
1个回答
0
投票
是因为我要回来
© www.soinside.com 2019 - 2024. All rights reserved.