
|
If you were logged in you would be able to see more operations.
|
|
|
|
Environment:
|
Windows XP SP2
|
|
| Build: |
7,573
|
| Severity: |
High
|
In this example there is a raw Map<K,V>.
If I run Generify... on this code, IDEA creates a syntax error.
package org.intellij;
import java.util.*;
/**
* User: alex
*/
public class TestGenerifyProducesBadCode
{
/*
I think the fact that this method is unused is possible
confusing IDEA? Still there is enough information there
to determine the type of ratingMap as Map<String,List<Integer>>
*/
protected static int unusedMethod(
Map ratingMap
) {
String[] nameA = new String[] {"Irida","Demetra","Selena"};
int highestScore = 0;
for (String name : nameA) {
List ratings = (List) ratingMap.get(name);
if (ratings == null) {
ratings = new ArrayList();
}
if (ratings.size() != 0) {
int score = getMax(ratings);
if (score > highestScore) {
highestScore = score;
}
}
}
return highestScore;
}
public static int getMax(List<Integer> events) {
int max = 0;
for (Integer score : events) {
if (score > max) {
max = score;
}
}
return max;
}
}
If I run Generify.. on it, IDEA creates a compile error.
package org.intellij;
import java.util.*;
/**
* User: alex
*/
public class TestGenerifyProducesBadCode
{
/*
I think the fact that this method is unused is possible
confusing IDEA? Still there is enough information there
to determine the type of ratingMap as Map<String,List<Integer>>
*/
protected static int unusedMethod(
Map ratingMap
) {
String[] nameA = new String[] {"Irida","Demetra","Selena"};
int highestScore = 0;
for (String name : nameA) {
List<Integer> ratings = ratingMap.get(name);
if (ratings == null) {
ratings = new ArrayList<Integer>();
}
if (ratings.size() != 0) {
int score = getMax(ratings);
if (score > highestScore) {
highestScore = score;
}
}
}
return highestScore;
}
public static int getMax(List<Integer> events) {
int max = 0;
for (Integer score : events) {
if (score > max) {
max = score;
}
}
return max;
}
}
If I use Eclipse 34m2, does almost the same as IDEA, except it puts a cast in where IDEA is creating
a compile error.
package org.intellij;
import java.util.*;
/**
* User: alex
*/
public class TestGenerifyProducesBadCode
{
/*
I think the fact that this method is unused is possible
confusing IDEA? Still there is enough information there
to determine the type of ratingMap as Map<String,List<Integer>>
*/
protected static int unusedMethod(
Map ratingMap
) {
String[] nameA = new String[] {"Irida","Demetra","Selena"};
int highestScore = 0;
for (String name : nameA) {
List<Integer> ratings = (List<Integer>) ratingMap.get(name);
if (ratings == null) {
ratings = new ArrayList<Integer>();
}
if (ratings.size() != 0) {
int score = getMax(ratings);
if (score > highestScore) {
highestScore = score;
}
}
}
return highestScore;
}
public static int getMax(List<Integer> events) {
int max = 0;
for (Integer score : events) {
if (score > max) {
max = score;
}
}
return max;
}
}
Looking at the code, I thought IDEA could fully Generify.. the code. If IDEA had generified..
the ratingMap parameter to Map<String,List<Integer>>, then it wouldn't have needed the cast.
I think at some point IDEA thinks it has ratingMap parameter parametized, and so it drops the
cast, but then later for some reason it doesn't end up Generifying ratingMap, which causes the
problem.
package org.intellij;
import java.util.*;
/**
* User: alex
*/
public class TestGenerifyProducesBadCode
{
/*
I think the fact that this method is unused is possible
confusing IDEA? Still there is enough information there
to determine the type of ratingMap as Map<String,List<Integer>>
*/
protected static int unusedMethod(
Map<String,List<Integer>> ratingMap
) {
String[] nameA = new String[] {"Irida","Demetra","Selena"};
int highestScore = 0;
for (String name : nameA) {
List<Integer> ratings = ratingMap.get(name);
if (ratings == null) {
ratings = new ArrayList<Integer>();
}
if (ratings.size() != 0) {
int score = getMax(ratings);
if (score > highestScore) {
highestScore = score;
}
}
}
return highestScore;
}
public static int getMax(List<Integer> events) {
int max = 0;
for (Integer score : events) {
if (score > max) {
max = score;
}
}
return max;
}
}
|
|
Description
|
In this example there is a raw Map<K,V>.
If I run Generify... on this code, IDEA creates a syntax error.
package org.intellij;
import java.util.*;
/**
* User: alex
*/
public class TestGenerifyProducesBadCode
{
/*
I think the fact that this method is unused is possible
confusing IDEA? Still there is enough information there
to determine the type of ratingMap as Map<String,List<Integer>>
*/
protected static int unusedMethod(
Map ratingMap
) {
String[] nameA = new String[] {"Irida","Demetra","Selena"};
int highestScore = 0;
for (String name : nameA) {
List ratings = (List) ratingMap.get(name);
if (ratings == null) {
ratings = new ArrayList();
}
if (ratings.size() != 0) {
int score = getMax(ratings);
if (score > highestScore) {
highestScore = score;
}
}
}
return highestScore;
}
public static int getMax(List<Integer> events) {
int max = 0;
for (Integer score : events) {
if (score > max) {
max = score;
}
}
return max;
}
}
If I run Generify.. on it, IDEA creates a compile error.
package org.intellij;
import java.util.*;
/**
* User: alex
*/
public class TestGenerifyProducesBadCode
{
/*
I think the fact that this method is unused is possible
confusing IDEA? Still there is enough information there
to determine the type of ratingMap as Map<String,List<Integer>>
*/
protected static int unusedMethod(
Map ratingMap
) {
String[] nameA = new String[] {"Irida","Demetra","Selena"};
int highestScore = 0;
for (String name : nameA) {
List<Integer> ratings = ratingMap.get(name);
if (ratings == null) {
ratings = new ArrayList<Integer>();
}
if (ratings.size() != 0) {
int score = getMax(ratings);
if (score > highestScore) {
highestScore = score;
}
}
}
return highestScore;
}
public static int getMax(List<Integer> events) {
int max = 0;
for (Integer score : events) {
if (score > max) {
max = score;
}
}
return max;
}
}
If I use Eclipse 34m2, does almost the same as IDEA, except it puts a cast in where IDEA is creating
a compile error.
package org.intellij;
import java.util.*;
/**
* User: alex
*/
public class TestGenerifyProducesBadCode
{
/*
I think the fact that this method is unused is possible
confusing IDEA? Still there is enough information there
to determine the type of ratingMap as Map<String,List<Integer>>
*/
protected static int unusedMethod(
Map ratingMap
) {
String[] nameA = new String[] {"Irida","Demetra","Selena"};
int highestScore = 0;
for (String name : nameA) {
List<Integer> ratings = (List<Integer>) ratingMap.get(name);
if (ratings == null) {
ratings = new ArrayList<Integer>();
}
if (ratings.size() != 0) {
int score = getMax(ratings);
if (score > highestScore) {
highestScore = score;
}
}
}
return highestScore;
}
public static int getMax(List<Integer> events) {
int max = 0;
for (Integer score : events) {
if (score > max) {
max = score;
}
}
return max;
}
}
Looking at the code, I thought IDEA could fully Generify.. the code. If IDEA had generified..
the ratingMap parameter to Map<String,List<Integer>>, then it wouldn't have needed the cast.
I think at some point IDEA thinks it has ratingMap parameter parametized, and so it drops the
cast, but then later for some reason it doesn't end up Generifying ratingMap, which causes the
problem.
package org.intellij;
import java.util.*;
/**
* User: alex
*/
public class TestGenerifyProducesBadCode
{
/*
I think the fact that this method is unused is possible
confusing IDEA? Still there is enough information there
to determine the type of ratingMap as Map<String,List<Integer>>
*/
protected static int unusedMethod(
Map<String,List<Integer>> ratingMap
) {
String[] nameA = new String[] {"Irida","Demetra","Selena"};
int highestScore = 0;
for (String name : nameA) {
List<Integer> ratings = ratingMap.get(name);
if (ratings == null) {
ratings = new ArrayList<Integer>();
}
if (ratings.size() != 0) {
int score = getMax(ratings);
if (score > highestScore) {
highestScore = score;
}
}
}
return highestScore;
}
public static int getMax(List<Integer> events) {
int max = 0;
for (Integer score : events) {
if (score > max) {
max = score;
}
}
return max;
}
}
|
Show » |
| There are no comments yet on this issue.
|
|