#8 COSArray.indexOf doesn't work correctly

closed-wont-fix
mtraut
None
5
2011-02-21
2011-02-20
Anonymous
No

I tried to detect whether the COSArray of a ColorSpace key from an image object contains the "/Indexed" value. I used following code but obtained an unexpected result (-1):

...
// possibly indexed raster picture
else if (type instanceof COSArray)
{
if (((COSArray)type).indexOf(PDColorSpace.CN_CS_Indexed) != -1)
{
...

The COSArray contains this entry but the indexOf method doesn't find it. I stepped into this method in debug mode and realized that COSArray.basicIndexOf() passes this "Indexed" entry but the comparison between the two object references does fail:

...
COSDocumentElement current = (COSDocumentElement) it.next();
if (containable == current) {
return i;
}
i++;
...

"containable" and "current" do have the same contents ("Indexed") but represent different instances with different references.

You can reproduce this behaviour with help of my example PDF from the attachments. The image object "7 0 obj" contains this ColorSpace entry within the image dictionary.

Discussion

  • Concerning object: 7 0 obj

     
    Attachments
  • mtraut
    mtraut
    2011-02-21

    I'm sorry that this behavior is not explicitly stated. But, as a matter of fact, array elements are handled by identity (same with "remove"). This is simply an optimization and fits to the use cases where complex objects are handled.

    If you explicitly need equality you should use the iterator and check manually.

    Btw. i think its more efficiently (and closer to the spec) to explicitly check for the first array element...

    if (((COSArray)type).get(0).equals(PDColorSpace.CN_CS_Indexed))

     
  • mtraut
    mtraut
    2011-02-21

    • milestone: 792084 -->
    • assigned_to: nobody --> mtraut
    • status: open --> closed-wont-fix