[ 
https://jira.duraspace.org/browse/DS-806?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Tim Donohue updated DS-806:
---------------------------

    Status: Open  (was: Received)

Definitely looks like a failure in the logic.

But, I'm not sure I understand what your proposed fix is?

You say:  "change the 'else if' for the 'else if (language == null)' to 'if 
(language == null)'. "   But, there is no 'else if (language==null)'?

I believe, what you mean, and what will correct the problem is to change the 
end of that long 'if/else if/else if' statement to be:

        if (!schema.equals(Item.ANY))
        {
            if (dcv.schema != null && !dcv.schema.equals(schema))
            {
                // The namespace doesn't match
                return false;
            }
        }

That will ensure that the overall logic of that method is the following:
(1) First, compare 'element', if there's a match, continue to #2 (else, return 
false)
(2) Next, compare 'qualifier', if there's a match, continue to #3 (else, return 
false)
(3) Next, compare 'language', if there's a match, continue to #4 (else, return 
false)
(4) Finally, compare 'schema', if there's a match then full match is complete & 
return true (else return false)

Admittedly, a part of me feels this method logic should be turned around a bit 
(compare in this order: schema, element, qualifier, language), to ensure you 
immediately return false if a schema doesn't match (as that's the 'top 
component' of a metadata field).  But, the general logic seems to be the same 
either way.

Admittedly, I haven't had a chance to test these changes locally, but this 
seems correct to me (and there is a definite flaw in the current logic).

> Item.match() incorrect logic for schema testing
> -----------------------------------------------
>
>                 Key: DS-806
>                 URL: https://jira.duraspace.org/browse/DS-806
>             Project: DSpace
>          Issue Type: Bug
>          Components: DSpace API
>    Affects Versions: 1.5.0, 1.5.1, 1.5.2, 1.6.0, 1.6.1, 1.6.2, 1.7.0
>            Reporter: Stuart Lewis
>            Priority: Blocker
>             Fix For: 1.7.1
>
>         Attachments: [DS-806]_junit_test.patch
>
>
> Item.match(String schema, String element, String qualifier, String language, 
> DCValue dcv) contains the following code:
>         if (language == null)
>         {
>             // Value must be null language to match
>             if (dcv.language != null)
>             {
>                 // Value is qualified, so no match
>                 return false;
>             }
>         }
>         else if (!language.equals(Item.ANY))
>         {
>             // Not a wildcard, so language must match exactly
>             if (!language.equals(dcv.language))
>             {
>                 return false;
>             }
>         }
>         else if (!schema.equals(Item.ANY))
>         {
>             if (dcv.schema != null && !dcv.schema.equals(schema))
>             {
>                 // The namespace doesn't match
>                 return false;
>             }
>         }
> Therefore, the schema is not being checked if the language of the metadata 
> field is empty (null) or set to Item.ANY.  This leads to the following case:
> dc.type = foo
> dc2.type = bar
> MyItem.getMetadata("dc", "type", null, null) should return 1 result 'foo'.
> Instead, it returns 'foo' and 'bar'.
> To fix, change the 'else if' for the 'else if (language == null)' to 'if 
> (language == null)'.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
https://jira.duraspace.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Dspace-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dspace-devel

Reply via email to