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

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

    Details

    • Type: False-Positive
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 6.1
    • Component/s: Rules
    • Labels:
      None

      Description

      public void myFunction(HttpServletRequest request) {
              HttpSession session = request.getSession();
      	
              Map<String, String> map = new HashMap<>();
              session.setAttribute("test with map", map); // false positive
      	
              HashMap<String, String> hashmap = new HashMap<>();
              session.setAttribute("test with hashmap", hashmap); // no error
      	
              List<String> list = new ArrayList<>(); 
          	session.setAttribute("test with list", list); // no error
          
              Set<String> set = new HashSet<>(); 
          	session.setAttribute("test with set", set); // no error
      } 

       

      Looks like in SONARJAVA-1810 we excluded collections like sets and arrays, still we report FP on variable declared as Map and assigned instance of HashMap.

      Reported in community thread https://community.sonarsource.com/t/fp-in-s2441-make-map-and-its-parameters-serializable-or-dont-store-it-in-the-session/11998

       

       

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                elena.vilchik Elena Vilchik
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: