Uploaded image for project: 'Sakai'
  1. Sakai
  2. SAK-17647 Clean up code via static code review sweep for 2.7
  3. SAK-17660

A couple of potential NPE's in Roster seen by static code review

    Details

    • Type: Sub-task
    • Status: CLOSED
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.7.0
    • Fix Version/s: 2.7.0, 2.8.0
    • Component/s: zz Roster [DO NOT USE]
    • Labels:
      None
    • Environment:
      Static code review 2-7.0-M2

      Description

      [1] org.sakaiproject.component.app.roster.RosterManagerImpl
      If IdUnusedException then NPE on line 316
      try

      { site = siteService().getSite(getSiteId()); }

      catch (IdUnusedException e)

      { log.error("getGroupsWithMember: " + e.getMessage(), e); }

      Collection<Group> groups = site.getGroups();

      [2]org.sakaiproject.tool.roster.RosterProfile
      If participant is Null then NPE at line 65

      services.eventTrackingService.post(services.eventTrackingService.newEvent("roster.view.profile",participant.getUser().getEid(),false));

      if (services.userDirectoryService.getCurrentUser().getId()
      .equals(userId)||SecurityService.isSuperUser())

      { // This user is looking at him/her self or isSuperUser return "completeProfile"; }

      if (participant == null || participant.getProfile() == null) {

      [3] org.sakaiproject.component.app.roster.RosterManagerImpl
      Line 338

      Method concatenates strings using + in a loop
      The method seems to be building a String using concatenation in a loop. In each iteration, the String is converted to a StringBuffer/StringBuilder, appended to, and converted back to a String. This can lead to a cost quadratic in the number of iterations, as the growing string is recopied in each iteration.
      Better performance can be obtained by using a StringBuffer (or StringBuilder in Java 1.5) explicitly.
      For example:
      // This is bad
      String s = "";
      for (int i = 0; i < field.length; ++i)

      { s = s + field[i]; }

      // This is better
      StringBuffer buf = new StringBuffer();
      for (int i = 0; i < field.length; ++i)

      { buf.append(field[i]); }

      String s = buf.toString();

      String groupsString = "";
      for (Group group : groups)
      {
      Member member = group.getMember(userId);
      if (member !=null)

      { groupsString = groupsString + group.getTitle() + ", "; }

      }

        Gliffy Diagrams

          Zeplin

            Attachments

              Activity

                People

                Assignee:
                dhorwitz David Horwitz
                Reporter:
                a.m.berg@uva.nl Alan Berg
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:

                    Git Integration