Issue Details (XML | Word | Printable)

Key: DIRSERVER-664
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Emmanuel Lecharny
Reporter: Giamma
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Directory ApacheDS

ExceptionService.modify() is not generating the correct exception

Created: 06/Jul/06 07:39 AM   Updated: 15/Feb/09 01:34 PM
Return to search
Component/s: None
Affects Version/s: 1.0-RC4
Fix Version/s: None

Time Tracking:
Not Specified

Resolution Date: 27/Jul/06 11:36 PM


 Description  « Hide

When trying to modify an attribute with an existing value, the following exception should be generated:
LdapAttributeInUseException( "Trying to add existing value 'XYZ' to attribute ABC");

But instead the code is generating a IndexOutOfBoundsException because there is a bug in the code that is generating the correct exception.

This is the wrong code:

 public void modify( NextInterceptor nextInterceptor, Name name, ModificationItem[] items ) throws NamingException
    {
        // check if entry to modify exists
        String msg = "Attempt to modify non-existant entry: ";
        assertHasEntry( nextInterceptor, msg, name );

        Attributes entry = nexus.lookup( name );
        for ( int ii = 0; ii < items.length; ii++ )
        {
            if ( items[ii].getModificationOp() == DirContext.ADD_ATTRIBUTE )
            {
                Attribute modAttr = items[ii].getAttribute();
                Attribute entryAttr = entry.get( modAttr.getID() );

                if ( entryAttr != null )
                {
                    for ( int jj = 0; jj < modAttr.size(); jj++ )
                    {
                        if ( entryAttr.contains( modAttr.get( jj ) ) )
                        {
                            throw new LdapAttributeInUseException( "Trying to add existing value '"
                                    + modAttr.get( ii ) + "' to attribute " + modAttr.getID() ); <----- HERE IS THE PROBLEM, should use modAttr.get( jj )
                        }
                    }
                }
            }
        }
        nextInterceptor.modify( name, items );
    }



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Emmanuel Lecharny added a comment - 27/Jul/06 11:36 PM
Thanks a lot Giamma !

The fix was perfect !

I added a junit test case just in case, and fixed the code the way you proposed to do.

Gianmaria Clerici added a comment - 07/Nov/06 06:22 AM

   [[ Old comment, sent by email on Thu, 27 Jul 2006 19:43:29 -0700 ]]

You are welcome.

But I can do better then that :-)

CIAO


Gianmaria Clerici aka Giamma
Email <mailto:gianmaria@giamma.com>gianmaria@giamma.com
Mobile +1 415 290-9502 Home +1 415 626-8394
AOL/YAHOO IM giamma13 SMS giamma@tmomail.net
    * <http://dj.giamma.com/&gt;dj.giamma.com
    * www.triplepower.org
    * <http://people.tribe.net/giamma/blog&gt;people.tribe.net/giamma/blog
    * www.flickr.com/photos/giamma
    * www.youtube.com/user/giamma

Emmanuel Lecharny added a comment - 15/Feb/09 01:34 PM
closed