String msg = "failed to modify entry " + req.getName();
String msg = "failed to modify entry " + req.getName() + ": " + e.getMessage();
    public void messageReceived( IoSession session, Object request ) throws Exception    {        ModifyRequest req = ( ModifyRequest ) request;        LdapResult result = req.getResultResponse().getLdapResult();        try        {            LdapContext ctx = SessionRegistry.getSingleton().getLdapContext( session, null, true );            if ( req.getControls().containsKey( ManageDsaITControl.CONTROL_OID ) )            {                ctx.addToEnvironment( Context.REFERRAL, "ignore" );            }            else            {                ctx.addToEnvironment( Context.REFERRAL, "throw" );            }            ctx.setRequestControls( ( Control[] ) req.getControls().values().toArray( EMPTY_CONTROLS ) );            Object[] mods = req.getModificationItems().toArray( EMPTY );            ctx.modifyAttributes( req.getName(), ( ModificationItem[] ) mods );        }        catch ( ReferralException e )        {            ReferralImpl refs = new ReferralImpl();            result.setReferral( refs );            result.setResultCode( ResultCodeEnum.REFERRAL );            result.setErrorMessage( "Encountered referral attempting to handle modify request." );            /* coming up null causing a NPE */            // result.setMatchedDn( e.getResolvedName().toString() );            do            {                refs.addLdapUrl( ( String ) e.getReferralInfo() );            }            while ( e.skipReferral() );            session.write( req.getResultResponse() );            return;        }        catch ( NamingException e )        {            String msg = "failed to modify entry " + req.getName();                        if ( IS_DEBUG )            {                msg += ":\n" + ExceptionUtils.getStackTrace( e );            }            ResultCodeEnum code;            if ( e instanceof LdapException )            {                code = ( ( LdapException ) e ).getResultCode();            }            else            {                code = ResultCodeEnum.getBestEstimate( e, req.getType() );            }            result.setResultCode( code );            result.setErrorMessage( msg );                        if ( ( e.getResolvedName() != null )                && ( ( code == ResultCodeEnum.NOSUCHOBJECT ) || ( code == ResultCodeEnum.ALIASPROBLEM )                    || ( code == ResultCodeEnum.INVALIDDNSYNTAX ) || ( code == ResultCodeEnum.ALIASDEREFERENCINGPROBLEM ) ) )            {                result.setMatchedDn( (LdapDN)e.getResolvedName() );            }            session.write( req.getResultResponse() );            return;        }        result.setResultCode( ResultCodeEnum.SUCCESS );        session.write( req.getResultResponse() );        return;    }