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)
请先登录再写评论。
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?
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!"
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
Ok, fine.
Meanwhile, ideas to chop down meaningless 'Local Code Analysis' category
are welcome.
-
Maxim Shafirov
http://www.jetbrains.com
"Develop with pleasure!"
Thanks Maxim.
Nick