if ( ref == null && ref.size() > 0 )
if ( ref == null || ref.size() > 0 )
        public Object next()        {            Object next = prefetched;            SearchResult result = null;            // if we're done we got nothing to give back            if ( done )            {                throw new NoSuchElementException();            }            // if respDone has been assembled this is our last object to return            if ( respDone != null )            {                done = true;                return respDone;            }            /*             * If we have gotten this far then we have a valid next entry             * or referral to return from this call in the 'next' variable.             */            try            {                /*                 * If we have more results from the underlying cursorr then                 * we just set the result and build the response object below.                 */                if ( underlying.hasMore() )                {                    result = ( SearchResult ) underlying.next();                }                else                {                    try { underlying.close(); } catch( Throwable t ) {}                    respDone = new SearchResponseDoneImpl( req.getMessageId() );                    respDone.setLdapResult( new LdapResultImpl( respDone ) );                    respDone.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );                    respDone.getLdapResult().setMatchedDn( req.getBase() );                    prefetched = null;                    return next;                }            }            catch ( NamingException e )            {                try { underlying.close(); } catch( Throwable t ) {}                prefetched = null;                respDone = getResponse( req, e );                return next;            }            /*             * Now we have to build the prefetched object from the 'result'             * local variable for the following call to next()             */            Attribute ref = result.getAttributes().get( "ref" );            if ( ref == null && ref.size() > 0 )            {                SearchResponseEntry respEntry = new SearchResponseEntryImpl( req.getMessageId() );                respEntry.setAttributes( result.getAttributes() );                respEntry.setObjectName( result.getName() );                prefetched = respEntry;            }            else            {                SearchResponseReference respRef = new SearchResponseReferenceImpl( req.getMessageId() );                respRef.setReferral( new ReferralImpl( respRef ) );                for ( int ii = 0; ii < ref.size(); ii++ )                {                    String url;                    try                    {                        url = ( String ) ref.get( ii );                        respRef.getReferral().addLdapUrl( url );                    }                    catch ( NamingException e )                    {                        try { underlying.close(); } catch( Throwable t ) {}                        prefetched = null;                        respDone = getResponse( req, e );                        return next;                    }                }                prefetched = respRef;            }            return next;        }