fb-contrib icon indicating copy to clipboard operation
fb-contrib copied to clipboard

UCC_UNRELATED_COLLECTION_CONTENTS false positive

Open boris-petrov opened this issue 7 years ago • 4 comments

I have a List<Object>. Any call to .add gives that warning.

boris-petrov avatar Jan 12 '18 11:01 boris-petrov

Yes, this is what the detector is looking for. It likely means that when you iterate this collection you are using instanceof checks to figure out what to do which is brittle. (Unless, of course, all you are doing with those objects are .hashCode or .equals, which then it's ok, but seems quite limited.

Anyway if you disagree with what this detector is doing, you should disable it.

mebigfatguy avatar Jan 12 '18 22:01 mebigfatguy

I see. In my case I'm using XAJB to generate Java from a DTD and it outputs methods like:

public List<Object> getNameOrSomethingOrSomethingElse()
...

In which case I have no other way other than adding elements to a List<Object> which are from completely different types...

Anyway, thanks for the answer. I'll leave you to think if there is anything you can do about that or close the issue. Thank you!

boris-petrov avatar Jan 15 '18 09:01 boris-petrov

Yeah, the JAXB generators are usually pretty lousy about generating code, not just for this, but other things as well. I usually add filters for findbugs to exclude any generated code as you can't really do anything about it anyway.

mebigfatguy avatar Jan 15 '18 13:01 mebigfatguy

Yes, but I use this List<Object> in my code so I have to suppress the warning there. Not so much of a deal though.

boris-petrov avatar Jan 15 '18 16:01 boris-petrov