You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by David Caruana <da...@alfresco.org> on 2005/09/20 18:28:01 UTC

Bug in TCK NodeTypeUtil.java?

The method getIllegalChildNodeType() can return a legal type.  This
happens if the first node type to come back from getAllNodeTypes() is in
the fact the type that is not wanted.  I must have been unlucky here.

A sub-type check is made, but not a type equality check.  I adjusted the
function by adding the following two lines:

   public static String getIllegalChildNodeType(NodeTypeManager manager,
                                                 String legalType)
            throws RepositoryException {

        NodeTypeIterator types = manager.getAllNodeTypes();
        while (types.hasNext()) {
            NodeType type = types.nextNodeType();
-->            if (!type.getName().equals(legalType)) {
                   NodeType superTypes[] = type.getSupertypes();
                   boolean isSubType = false;
                   for (int i = 0; i < superTypes.length; i++) {
                      String name = superTypes[i].getName();
                      if (name.equals(legalType)) {
                          isSubType = true;
                          break;
                      }
                 }
                 if (!isSubType) {
                    return type.getName();
                 }
-->          }
        }
        return null;
    }

I don't believe NodeType.getSupertypes() should return the supertypes
and itself in which case I think the current function would be fine.

Regards,
David Caruana
http://www.alfresco.org



Re: Bug in TCK NodeTypeUtil.java?

Posted by Marcel Reutegger <ma...@gmx.net>.
Hi David,

David Caruana wrote:
> The method getIllegalChildNodeType() can return a legal type.  This
> happens if the first node type to come back from getAllNodeTypes() is in
> the fact the type that is not wanted.  I must have been unlucky here.
> 
> A sub-type check is made, but not a type equality check.  I adjusted the
> function by adding the following two lines:
> 
>    public static String getIllegalChildNodeType(NodeTypeManager manager,
>                                                  String legalType)
>             throws RepositoryException {
> 
>         NodeTypeIterator types = manager.getAllNodeTypes();
>         while (types.hasNext()) {
>             NodeType type = types.nextNodeType();
> -->            if (!type.getName().equals(legalType)) {
>                    NodeType superTypes[] = type.getSupertypes();
>                    boolean isSubType = false;
>                    for (int i = 0; i < superTypes.length; i++) {
>                       String name = superTypes[i].getName();
>                       if (name.equals(legalType)) {
>                           isSubType = true;
>                           break;
>                       }
>                  }
>                  if (!isSubType) {
>                     return type.getName();
>                  }
> -->          }
>         }
>         return null;
>     }

thanks for the patch. I've committed the change as you suggested.
svn revision is: 290913

> I don't believe NodeType.getSupertypes() should return the supertypes
> and itself in which case I think the current function would be fine.

that's correct.

regards
  marcel