RFE: Inspections : Generics usage

We just hit a bug here and I was wondering if it would be possible to add an error check for this:

Map<Long, Integer> test = new HashMap<Long,Integer>();

test.get( "" );


This compiles and runs fine (except the intended lookup value never gets found since Map.get() takes an Object)

Would it be possible to add an inspection that could flag such usages of get() / contains() etc (basically all the Collection query methods) if you try and query a collection by anything other than the type parameter (in this case a Long)

5 comments
Comment actions Permalink

OK, I think I found an inspection that does this, although the warning/error message is a tad cryptic:

"For no non-null object of type 'String' can 'Map.get' return non-null value"


Maybe that text should be made a little more obvious?

Where in the error settings is this "Suspiscous Collection Usage" defined - I only found it by -]]> on the wawrning - where in the errors config tree does this thing live?

0
Comment actions Permalink

Local Code Analysis | Suspicious collection method call

I agree this should be in probable bugs though.

-


Maxim Shafirov
http://www.jetbrains.com
"Develop with pleasure!"


0
Comment actions Permalink


Although I strongly support the idea of JB and I standardizing bug categories, give me a couple of days clearing up the IG categories first. While "Probable bugs" is likely to still be there, some of the other categories ("Verbose or redundant", "Possibly confusing", "Class structure") are being sliced and diced into more descriptive and easily understood chunks.



--Dave Griffith

0
Comment actions Permalink

Ok, fine.
Meanwhile, ideas to chop down meaningless 'Local Code Analysis' category
are welcome.

-


Maxim Shafirov
http://www.jetbrains.com
"Develop with pleasure!"

Although I strongly support the idea of JB and I standardizing bug
categories, give me a couple of days clearing up the IG categories
first. While "Probable bugs" is likely to still be there, some of
the other categories ("Verbose or redundant", "Possibly confusing",
"Class structure") are being sliced and diced into more descriptive
and easily understood chunks.

--Dave Griffith



0
Comment actions Permalink

Thanks Maxim.

Nick

0

Please sign in to leave a comment.