UCC_UNRELATED_COLLECTION_CONTENTS false positive
I have a List<Object>. Any call to .add gives that warning.
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.
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!
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.
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.