← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11172: Fixed bug, nullpointer vulnerability in get max org unit levels method

 

------------------------------------------------------------
revno: 11172
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2013-06-08 10:02:30 +0200
message:
  Fixed bug, nullpointer vulnerability in get max org unit levels method
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitLevelStore.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitLevelStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitLevelStore.java	2013-04-15 17:06:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitLevelStore.java	2013-06-08 08:02:30 +0000
@@ -67,6 +67,8 @@
     {
         final String sql = "SELECT MAX(level) FROM orgunitlevel";
 
-        return jdbcTemplate.queryForObject( sql, Integer.class );
+        Integer level = jdbcTemplate.queryForObject( sql, Integer.class );
+        
+        return level != null ? level : 0;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java	2013-05-14 09:58:30 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java	2013-06-08 08:02:30 +0000
@@ -744,4 +744,18 @@
         assertNull( organisationUnitService.getOrganisationUnitLevel( idA ) );
         assertNull( organisationUnitService.getOrganisationUnitLevel( idB ) );
     }
+    
+    @Test
+    public void getMaxLevels()
+    {
+        assertEquals( 0, organisationUnitService.getMaxOfOrganisationUnitLevels() );
+
+        OrganisationUnitLevel levelA = new OrganisationUnitLevel( 1, "National" );
+        OrganisationUnitLevel levelB = new OrganisationUnitLevel( 2, "District" );
+
+        organisationUnitService.addOrganisationUnitLevel( levelA );
+        organisationUnitService.addOrganisationUnitLevel( levelB );
+
+        assertEquals( 2, organisationUnitService.getMaxOfOrganisationUnitLevels() );
+    }
 }