Directory ApacheDS
  1. Directory ApacheDS
  2. DIRSERVER-952

NPE when using createSubcontext() with embedded server

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0.2
    • Fix Version/s: 1.0.3
    • Component/s: core
    • Labels:
      None
    • Environment:
      Windows 2003, JDK 1.5

      Description

      We've found a problem with DS 1.0.2. This problem only exists when running with DS embedded in the same VM.
      Running the same code remotely (outside of DS VM) works fine.

      Example code:

      ....
      Attributes attrs = new BasicAttributes();
      attrs.put("objectClass", "organizationalUnit");
      attrs.put("description", "Test OU");

      DirContext subContext = context.createSubcontext("ou=Test", attrs);

      Exception from createSubcontext():

      Caused by: java.lang.NullPointerException
      at org.apache.directory.shared.ldap.util.AttributeUtils.containsValueCaseIgnore(AttributeUtils.java:309)
      at org.apache.directory.server.core.schema.SchemaService.assertAllAttributesAllowed(SchemaService.java:1806)
      at org.apache.directory.server.core.schema.SchemaService.check(SchemaService.java:1624)
      at org.apache.directory.server.core.schema.SchemaService.add(SchemaService.java:1636)
      at org.apache.directory.server.core.interceptor.InterceptorChain$Entry$1.add(InterceptorChain.java:1181)
      ... 130 more

      If you change the BasicAttributes() constructor call to:

      Attributes attrs = new BasicAttributes( true );

      it works fine.

        Activity

        Hide
        Emmanuel Lecharny added a comment -

        Beside the fact we have a NPE, this behaviour is expected as the BasicAttributes() has been created as caseSensitive in the caller code.

        What happens is that you created the attribute using "objectClass" when we are looking for "objectclass" in the code ( we do attr.getAttribute( "objectclass" ) ). We have two options here :

        • throwing an explicit exception instead of a NPE
        • writing some costly code to iterate through all the attributes, like :

        ...
        if ( objectClass == null )
        {
        NamingEnumeration ids = attributes.getIDs();

        while ( ids.hasMoreElements() )
        {
        String id = (String)ids.nextElement();

        if ( "objectclass".compareToIgnoreCase( id ) == 0 )

        { objectClass = attributes.get( id ); break; }

        }

        if ( objectClass == null )

        { throw new NamingException( "No ObjectClass attribute in the entry" ); }

        }
        ...

        Even if I personnaly hate JNDI for allowing users to create case sensitive BasicAttributes(), I think we should protect the server from it because all our users will do this mistake at least once (and I did this mistake so many times ... !). So I will implement this loop, and I will also do it in 1.5 version, because we have the very same error.

        Show
        Emmanuel Lecharny added a comment - Beside the fact we have a NPE, this behaviour is expected as the BasicAttributes() has been created as caseSensitive in the caller code. What happens is that you created the attribute using "objectClass" when we are looking for "objectclass" in the code ( we do attr.getAttribute( "objectclass" ) ). We have two options here : throwing an explicit exception instead of a NPE writing some costly code to iterate through all the attributes, like : ... if ( objectClass == null ) { NamingEnumeration ids = attributes.getIDs(); while ( ids.hasMoreElements() ) { String id = (String)ids.nextElement(); if ( "objectclass".compareToIgnoreCase( id ) == 0 ) { objectClass = attributes.get( id ); break; } } if ( objectClass == null ) { throw new NamingException( "No ObjectClass attribute in the entry" ); } } ... Even if I personnaly hate JNDI for allowing users to create case sensitive BasicAttributes(), I think we should protect the server from it because all our users will do this mistake at least once (and I did this mistake so many times ... !). So I will implement this loop, and I will also do it in 1.5 version, because we have the very same error.
        Hide
        Emmanuel Lecharny added a comment -

        A patch has been applied :
        http://svn.apache.org/viewvc?view=rev&rev=543737
        http://svn.apache.org/viewvc?view=rev&rev=543738

        A test check that the server works well even if injecting BasicAttributes() :
        http://svn.apache.org/viewvc?view=rev&rev=543738

        Show
        Emmanuel Lecharny added a comment - A patch has been applied : http://svn.apache.org/viewvc?view=rev&rev=543737 http://svn.apache.org/viewvc?view=rev&rev=543738 A test check that the server works well even if injecting BasicAttributes() : http://svn.apache.org/viewvc?view=rev&rev=543738
        Show
        Emmanuel Lecharny added a comment - The problem was also existing in 1.5. Fixed : http://svn.apache.org/viewvc?view=rev&rev=543762 http://svn.apache.org/viewvc?view=rev&rev=543763 http://svn.apache.org/viewvc?view=rev&rev=543764
        Hide
        Emmanuel Lecharny added a comment -

        closed

        Show
        Emmanuel Lecharny added a comment - closed

          People

          • Assignee:
            Emmanuel Lecharny
            Reporter:
            Simon Temple
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development