Uploaded image for project: 'Sakai'
  1. Sakai
  2. SAK-19081 2.8 Static code review sweep
  3. SAK-19447

Static code sweep - metaobj - 2.8 sweep

    XMLWordPrintable

    Details

    • Type: Sub-task
    • Status: CLOSED
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.8.0
    • Fix Version/s: 2.7.2, 2.8.0
    • Component/s: Metaobj
    • Labels:
      None
    • Environment:
      Source code

      Description

      MetaObj

      Comparison of String objects using == or !=
      This code compares java.lang.String objects for reference equality using the == or != operators. Unless both strings are either constants in a source file, or have been interned using the String.intern() method, the same string value may be represented by two different String objects. Consider using the equals(Object) method instead.

      1) FileDownloadServlet - Line 133
      response.setHeader("Content-Disposition", "attachment"
      + ((filename != null && filename != "") ? ";filename=\"" + filename + "\"" : ""));

      2) What happens if objectFile.delete fails
      XMLElementHome - Line 130

      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();

      3,4)
      ImportStructuredArtifactDefinitionController
      Line 161 - names += resource.getProperties().getProperty(resource.getProperties().getNamePropDisplayName()) + " ";
      StructuredArtifactDefinitionManagerImpl - Line 210
      query += ",";

      5,6,7,8)
      Inefficient use of keySet iterator instead of entrySet iterator
      This method accesses the value of a Map entry, using a key that was retrieved from a keySet iterator. It is more efficient to use an iterator on the entrySet of the map, to avoid the Map.get(key) lookup.

      FormCreateResourceHelper - Line 73 - List homesList = homes.get(site.getId());
      HomeFactoryBase - Line 79 - if (requiredHomeType.isInstance(homes.get(key))) {
      HttpServletHelper - Line 89 - if (map.get(key) == null) {
      HttpServletHelper - Line 124 - if (map.get(key) == null) {

      9) Is this work in progress?
      ComplexSchemaNodeImpl - Line 184

      if (orderDependant)

      { // todo add ordering check here }

        Gliffy Diagrams

          Zeplin

            Attachments

              Activity

                People

                Assignee:
                chmaurer@iupui.edu Chris Maurer
                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