Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-2065

Fields in non-serializable classes should not be "transient"

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Message:
      Remove the "transient" modifier from this field.
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Default Quality Profiles:
      Sonar way
    • Covered Languages:
      Java
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      2min
    • Analysis Scope:
      Main Sources, Test Sources
    • FindBugs:
      SE_TRANSIENT_FIELD_OF_NONSERIALIZABLE_CLASS

      Description

      transient is used to mark fields in a Serializable class which will not be written out to file (or stream). In a class that does not implement Serializable, this modifier is simply wasted keystrokes, and should be removed.

      Noncompliant Code Example

      class Vegetable {  // does not implement Serializable
        private transient Season ripe;  // Noncompliant
        // ...
      }
      

      Compliant Solution

      class Vegetable {
        private Season ripe;
        // ...
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              ann.campbell.2 Ann Campbell
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: