Search code examples
javaobjectfindbugs

FindBugs Integer not compatible with expected argument type?


I am working on an assignment and I thought I figured out the issue, but I am getting the same results. Using the FindBugs application I was able to see a big with the following line of code:

out.writeObject(accountMap.get(i));

I received a bug that said:

Integer is incompatible with expected argument type String in...

So I corrected it by converting the int to a String with:

out.writeObject(accountMap.get(Integer.toString(i)));

With the same bug results. Am I misunderstanding something?


Solution

  • I recreated your problem and Findbugs found the same error. So far so good.

    Integer is incompatible with expected argument type String in ...(String[]) [Scariest(1), High confidence]
    

    Then I applied your change (Integer.toString(i)) and discovered when running Findbugs again, the bug cleared (which differs from your observation).

    I suspect you did not re-run findbugs?

    I tested with Findbugs version: 3.0.1.20150306-5afe4d1

    PS: Here is some history as to why there is a bug at all (relating to Map#get not using generics): Why is java.util.Map.get(...) not generic?