click here for details... Sakai Executive Director Position Search now open
Issue Details (XML | Word | Printable)

Key: SAK-17659
Type: Sub-task Sub-task
Status: Closed Closed
Resolution: Fixed
Priority: Critical Critical
Assignee: Noah Botimer
Reporter: Alan Berg
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Sakai
SAK-17647

potential NPE's and s resource leaks in OSP found by static code review

Created: 07-Jan-2010 03:15   Updated: Monday 08:39 AM
Component/s: OSP: Other
Affects Version/s: 2.7.0-b01
Fix Version/s: 2.7.0-b05, 2.8.0 [Tentative]

Time Tracking:
Not Specified

File Attachments: 1. Text File metaobj.txt (5 kB)
2. Text File m2_osp.txt (18 kB)
3. Text File m2_osp_literals.txt (69 kB)
4. Text File reports.txt (3 kB)

Environment: Static code review of 2-7-M2 tag
Issue Links:
Relate
 

2.7.x Status: Closed
2.6.x Status: Closed
2.5.x Status: None
2.4.x Status: None


 Description  « Hide
See, we are talking around 40 defects that should be straightforward to clean up. Mostly a question of moving if statements or extra try catch or finally.

http://builds.sakaiproject.org/code_review/ad-hoc/tags/2.7.0-M2/%20metaobj.txt
http://builds.sakaiproject.org/code_review/ad-hoc/tags/2.7.0-M2/m2_osp.txt



 All   Comments   Work Log   Change History   Subversion Commits   git Commits      Sort Order: Ascending order - Click to sort in descending order
Alan Berg added a comment - 08-Jan-2010 00:55
Also checked reports:

See: http://www.ibm.com/developerworks/java/library/j-jtp03216.html

[1] org.sakaiproject.reports.logic.impl.LoadArtifactResultProcessor
Failure to close statement line 274, need to make non anonymous and expressly close in finally

protected void loadArtifactTypes(String artifactIds, Map<String, ArtifactHolder> artifactsToLoad) {
      Connection conn = null;
      ResultSet rs = null;
      try {
         conn = getDataSource().getConnection();
         rs = conn.createStatement().executeQuery(
               "select id, sub_type from dw_resource where id in (" + artifactIds + ")");
         while (rs.next()) {
            String id = rs.getString(1);
            String type = rs.getString(2);
            ArtifactHolder holder = (ArtifactHolder) artifactsToLoad.get(id);
            if (holder != null) {
               holder.artifactType = type;
            }
         }
      }
      catch (SQLException e) {
         logger.error("", e);
         throw new RuntimeException(e);
      }
      finally {
         //ensure that the results set is clsoed
         if (rs != null) {
            try {
               rs.close();
            } catch (SQLException e) {
               if (logger.isDebugEnabled()) {
                  logger.debug("loadArtifactTypes(String, Map) caught " + e);
               }
            }
         }
         //ensure that the connection is closed
         if (conn != null) {
            try {
               conn.close();
            }
            catch (SQLException e) {
               if (logger.isDebugEnabled()) {
                  logger.debug("loadArtifactTypes(String, Map) caught " + e);
            }
            }
         }
      }
   }


[2] org.sakaiproject.reports.logic.impl.ReportsManagerImpl
Line 1271 Useless object creation, result never used
            JDOMResult result = new JDOMResult();


[3] org.sakaiproject.reports.logic.impl.ReportsManagerImpl
NPE if scheduler is null line 2054
if (scheduler == null) {
            logger.error("Scheduler is down!");
        }
        JobDetail jd = null;
        try {

            JobBeanWrapper job = getJobBeanWrapper();
            if (job != null) {

                jd = scheduler.getJobDetail(report.getReportId().toString(), reportGroup);


[4,5] org.sakaiproject.reports.logic.impl.ReportsManagerImpl

Failure to close InputStream can cause File descriptor leakage

  InputStream stream = wrapper.getParentClass().getResourceAsStream(wrapper.getDefinitionFileLocation());
 if (wrapper.getParentClass().getResourceAsStream(xsl.getXslLink()) != null){


Wow this is difficult, the whole method should be looked at as by catching Exception with
        catch (Exception e) {
            throw new RuntimeException("Loaded report def failed", e);
        }

You are hiding java.io.Exceptions etc, that have to be closed properly. I would suggest re-implementing the try catch block as a series with a finally. The anonymous creation of streams etc. should be removed.

Alan Berg added a comment - 05-Feb-2010 02:02
A speedy resolution to this review, will allow QA to test as part of the 2.7 QA season. Please review the progress already made by SAK-17647

Beth Kirschner added a comment - 04-Mar-2010 05:38
Noah, is SAK-18127 the problem you mentioned that was related to this ticket?

Noah Botimer added a comment - 15-Mar-2010 08:39
These are complete from my perspective. I am not aware of any problems at present. The reports change has been reverted and the tool is starting up.