Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-3023

FP S2118: consider type of assigned expressions for properties/variables

    Details

    • Type: False-Positive
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.11
    • Component/s: Rules
    • Labels:
      None

      Description

      RSPEC-2118

      When property is final and/or private in order to be sure that its type is Serializable we can check types of expressions assigned to it. For local variable the same should be done regardless of its modifiers.

        final Map<Integer, List<Object>> cacheProp = new HashMap<>();
      
        void foo() {
          Map<Integer, List<Object>> cacheVar;
          cacheVar = new HashMap<>();
          try (FileOutputStream fos = new FileOutputStream(""); ObjectOutputStream oos = new ObjectOutputStream(fos)) {
            oos.writeObject(cache); // FP
            oos.writeObject(cacheVar); // Compliant for local vars : tracking real type should be resolved via MMF-1580
          } catch (final Exception e) {
            e.printStackTrace();
          }
        }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                nicolas.peru Nicolas Peru
                Reporter:
                elena.vilchik Elena Vilchik
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: