db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Fox (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (TORQUE-300) AbstractBaseManager.getOMs method has a bug
Date Fri, 30 Aug 2013 01:25:51 GMT

     [ https://issues.apache.org/jira/browse/TORQUE-300?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Thomas Fox resolved TORQUE-300.
-------------------------------

       Resolution: Fixed
    Fix Version/s: 4.1
         Assignee: Thomas Fox

I think that a method returning a lsit should never return null.
It always turns out to be a pain to check a result list for null.
So I have modified the method such that it returns an empty list if null or an empty list
is passed in.
This change also changes the behaviour of the getInstances() methods in the genereated Manager
classes likewise.

A test case was added in the Torque test project to check this behaviour.
                
> AbstractBaseManager.getOMs method has a bug
> -------------------------------------------
>
>                 Key: TORQUE-300
>                 URL: https://issues.apache.org/jira/browse/TORQUE-300
>             Project: Torque
>          Issue Type: Bug
>          Components: Runtime
>    Affects Versions: 3.3, 4.0
>            Reporter: Youngho Cho
>            Assignee: Thomas Fox
>            Priority: Minor
>              Labels: patch
>             Fix For: 4.1
>
>
> AbstractBaseManager.getOMs method returns null when input ids is empty list.
> I think this behavior is a bug.
> If input ids list is null than returns null is ok
> But if input ids list is not null but empty list than it should not return null but return
empty list.
> Here is a patch against 3.3
> @@ -21,6 +21,7 @@ package org.apache.torque.manager;
>  
>  import java.lang.ref.WeakReference;
>  import java.util.Arrays;
> +import java.util.Collections;
>  import java.util.List;
>  import java.util.ArrayList;
>  import java.util.Map;
> @@ -376,11 +377,16 @@ public abstract class AbstractBaseManager
>      protected List getOMs(List ids, boolean fromCache)
>          throws TorqueException
>      {
> -        List oms = null;
> -        if (ids != null && ids.size() > 0)
> +        if(ids == null)
>          {
> -            // start a new list where we will replace the id's with om's
> -            oms = new ArrayList(ids);
> +            return null;
> +        }
> +        if(ids.isEmpty())
> +        {
> +            return Collections.EMPTY_LIST;            
> +        }
> +        // start a new list where we will replace the id's with om's
> +        List oms = new ArrayList(ids);
>              List newIds = new ArrayList(ids.size());
>              for (int i = 0; i < ids.size(); i++)
>              {
> @@ -426,7 +432,6 @@ public abstract class AbstractBaseManager
>                      }
>                  }
>              }
> -        }
>          return oms;
>      }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message