# squid:S1948 False positive when field type is not-serializable but assigned serializable object

**URL:** <https://community.sonarsource.com/t/squid-s1948-false-positive-when-field-type-is-not-serializable-but-assigned-serializable-object/16583>\
**Category:** SonarQube Cloud\
**Tags:** java\
**Created:** [November 13, 2019, 11:38am UTC](https://community.sonarsource.com/t/squid-s1948-false-positive-when-field-type-is-not-serializable-but-assigned-serializable-object/16583 "2019-11-13T11:38:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maruTA-bis5](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/maruta-bis5/32/7562_2.png) [@maruTA-bis5](https://community.sonarsource.com/u/maruTA-bis5)\
**Post date:** [November 13, 2019, 11:38am UTC](https://community.sonarsource.com/t/squid-s1948-false-positive-when-field-type-is-not-serializable-but-assigned-serializable-object/16583/1 "2019-11-13T11:38:12Z")

</div>

- versions used
  - SonarQube 8.0.0 Community, sonar-maven-plugin 3.7.0-1746, SonarJava 5.14.0.18788
  - SonarCloud, sonar-maven-plugin 3.7.0-1746

- minimal code sample to reproduce

```java
package net.bis5.s1948;

import org.primefaces.model.*;
import java.io.*;

public class S1948App2 implements Serializable {

    // False positive: Make "rootNode" transient or serializable.
    private TreeNode rootNode = new DefaultTreeNode("root node", null);

    // False positive: Make "finalRootNode" transient or serializable.
    private final TreeNode finalRootNode = new DefaultTreeNode("root node", null);

    // False positive: Make "modifiedRootNode" transient or serializable.
    // (IMHO, I think that is not necessarily that means false positive because this field is modifiable through public setter.)
    private TreeNode modifiableRootNode = new DefaultTreeNode("root node", null);

    public TreeNode getRootNode() {
        return rootNode;
    }

    public TreeNode getFinalRootNode() {
        return finalRootNode;
    }

    public TreeNode getModifiableRootNode() {
        return modifiableRootNode;
    }

    public void setModifiableRootNode(TreeNode node) {
        this.modifiableRootNode = node;
    }
}

```

- `org.primefaces.model.TreeNode` is interface and is _not_ extends java.io.Serializable ([https://www.primefaces.org/docs/api/7.0/org/primefaces/model/TreeNode.html](https://www.primefaces.org/docs/api/7.0/org/primefaces/model/TreeNode.html))
- `org.primefaces.model.DefaultTreeNode` is class implements TreeNode and Serializable ([https://www.primefaces.org/docs/api/7.0/org/primefaces/model/DefaultTreeNode.html](https://www.primefaces.org/docs/api/7.0/org/primefaces/model/DefaultTreeNode.html))

There is sample project:

- Source: [https://github.com/maruTA-bis5/sandbox-java/tree/sonarqube-s1948-primefaces-treenode/sonarqube/sonarjava-fp-test](https://github.com/maruTA-bis5/sandbox-java/tree/sonarqube-s1948-primefaces-treenode/sonarqube/sonarjava-fp-test)
- Report: [https://sonarcloud.io/project/issues?branch=sonarqube-s1948-primefaces-treenode&id=net.bis5%3Asonarjava-fp-test&open=AW5kX2ZkJDfQyOFoW0Ox&resolved=false&rules=squid%3AS1948&types=CODE\_SMELL](https://sonarcloud.io/project/issues?branch=sonarqube-s1948-primefaces-treenode&id=net.bis5%3Asonarjava-fp-test&open=AW5kX2ZkJDfQyOFoW0Ox&resolved=false&rules=squid%3AS1948&types=CODE_SMELL)

---

<div class="post-metadata">

**Author:** ![Michael](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/michael/32/43_2.png) [@Michael](https://community.sonarsource.com/u/Michael)\
**Post date:** [August 19, 2020, 3:55pm UTC](https://community.sonarsource.com/t/squid-s1948-false-positive-when-field-type-is-not-serializable-but-assigned-serializable-object/16583/3 "2020-08-19T15:55:27Z")

</div>

Hey @maruTA-bis5,

First, let me apologize for the veeeeery long time it took to answer you, and thank you for your reproducer. This is indeed an FP to me. If the initializer type is serializable, then there is no such issue.

I created the following ticket to handle it: [SONARJAVA-3504](https://jira.sonarsource.com/browse/SONARJAVA-3504)

Cheers,  
Michael

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [August 26, 2020, 3:56pm UTC](https://community.sonarsource.com/t/squid-s1948-false-positive-when-field-type-is-not-serializable-but-assigned-serializable-object/16583/5 "2020-08-26T15:56:22Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
