Findbugs meldet "is transient but isn't set by deserialization"

ElBobby

Mitglied
Moin allerseits,

ich erfahre gerade seitens maven-fingbugs-plugin die oben angesprochene Fehlermeldung.

Code:
INFO] --- findbugs-maven-plugin:3.0.4:check (default) @ mm-webapp ---
[INFO] BugInstance size is 21
[INFO] Error size is 0
[INFO] Total bugs: 21
[INFO] The field de.peng.project.manager.AdminHouseholdManager.householdDao is transient but isn't set by deserialization [de.peng.project.manager.AdminHouseholdManager] In AdminHouseholdManager.java SE_TRANSIENT_FIELD_NOT_RESTORED
[...]
[INFO] The field de.peng.project.manager.finance.StatisticsManager.statisticsService is transient but isn't set by deserialization [de.peng.project.manager.finance.StatisticsManager] In StatisticsManager.java SE_TRANSIENT_FIELD_NOT_RESTORED

Die Konfiguration für das Plugin sieht wie folgt aus:
XML:
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
                <version>3.0.4</version>
                <configuration>
                    <!-- Enables analysis which takes more memory but finds more bugs. If
                        you run out of memory, changes the value of the effort element to 'Low'. -->
                    <effort>Max</effort>
                    <!-- Reports all bugs (other values are medium and max) -->
                    <threshold>Low</threshold>
                    <!-- Produces XML report -->
                    <xmlOutput>true</xmlOutput>
                    <!-- Configures the directory in which the XML report is created -->
                    <findbugsXmlOutputDirectory>${project.build.directory}/findbugs</findbugsXmlOutputDirectory>
                </configuration>
                <executions>
                    <!-- Ensures that FindBugs inspects source code when project is compiled. -->
                    <execution>
                        <phase>verify</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
</plugin>

Eine betroffene Klasse ist diese hier:
Java:
@Named(value = "adminHouseholdManager")
@SessionScoped
public class AdminHouseholdManager implements Serializable {

    /**
     * GUID.
     */
    private static final long serialVersionUID = -2029754623262293051L;

    /**
     * Constant alter.
     */
    private static final String ALTER = "alter";

    /**
     * Constant add.
     */
    private static final String ADD = "add";

    /**
     * {@link LoginManager} for getting {@link User}.
     */
    @Inject
    private LoginManager loginManager;

    /**
     * DAO for {@link Household}s.
     */
    @Inject
    private transient HouseholdDao householdDao;
   
    [...]

Die Klasse AdminHouseholdManager wird entsprechend über die JSPs genutzt und muss Serializable implementieren. Das Feld LoginManager ist ebenfalls eine mit SessionScoped annotierte Klasse. Aber, das Feld HouseholdDao (Interface [Apache Deltaspike Data Project]) ist transient, es muss nicht serialisiert werden. Warum also der Fehler.

Noch verwirrender ist, dass die Meldung von Findbugs erst mit dem OpenJdk11 aufkam.

Ich kann nun einfach das Level von max auf min runterstellen oder einfach ein nobug aufführen. Aber vllt missverstehe ich was und Findbugs hat Recht.
Hat da jemand eine Meinung?
 
Zuletzt bearbeitet:

LimDul

Top Contributor
Es ist hilfreich, die Dokumentation dazu zu lesen:
Se: Transient field that isn't set by deserialization. (SE_TRANSIENT_FIELD_NOT_RESTORED)
This class contains a field that is updated at multiple places in the class, thus it seems to be part of the state of the class. However, since the field is marked as transient and not set in readObject or readResolve, it will contain the default value in any deserialized instance of the class.

Sprich, die Variable wird genutzt, aber nicht im Rahmen der deserialisation, gesetzt. Jetzt musst du für dich klären, wenn ein Objekt "über die Leitung" geschickt wird, hast du dann ein Problem? Weil dann wäre das Feld null. Wenn nein, dann würde ich ein entsprechend Supress dran machen mit einer Begründung. Wir haben z.B. bei uns ein oder anderen Stellen folgendes stehen:

Java:
@SuppressFBWarnings(value = "NP_STORE_INTO_NONNULL_FIELD", justification = "CDI")
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
A Mapping mit transient fields Application Tier 2

Ähnliche Java Themen

Neue Themen


Oben