← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9186: made DefaultObjectBridge.getObject check for NPE when creating error message

 

------------------------------------------------------------
revno: 9186
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-12-06 12:21:56 +0300
message:
  made DefaultObjectBridge.getObject check for NPE when creating error message
modified:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.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-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java	2012-10-25 16:44:59 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java	2012-12-06 09:21:56 +0000
@@ -262,13 +262,28 @@
         {
             return objects.iterator().next();
         }
-        else if ( objects.size() > 1 )
-        {
-            log.debug( "Multiple objects found for " + object + ", object discarded, returning null." );
-        }
         else
         {
-            log.debug( "No object found for " + object + ", returning null." );
+            String objectName = null;
+
+            try
+            {
+                // several of our domain objects build toString based on several properties, which is not checked for
+                // null, which means that a NPE is very likely.
+                objectName = object.toString();
+            }
+            catch ( NullPointerException ignored )
+            {
+            }
+
+            if ( objects.size() > 1 )
+            {
+                log.debug( "Multiple objects found for " + objectName + ", object discarded, returning null." );
+            }
+            else
+            {
+                log.debug( "No object found for " + objectName + ", returning null." );
+            }
         }
 
         return null;