-
Bug
-
Resolution: Fixed
-
P3
-
5.0, 6
-
b65
-
generic
-
generic
-
Verified
Tried on Linux JDK build 1.6.0-auto-094
Compiler will fail to find the location of [serial] warnings for anonymous inner classes. It will always gives the last method or the last variable of the class as the location of warning, if the class is blank i.e. no methods or variables then compiler will not give any line number.
Please see the following code:
<code>
import java.util.List;
import java.util.ArrayList;
public class Test13{
@SuppressWarnings("unchecked")
public void anonymousMethod(){
List list = new ArrayList<String>(){
static final long serialVersionUID = 1;
List list = new ArrayList<Integer>();
public List<Integer> getMyList(){
final List floatList = new ArrayList<Float>(){
List integerList = new ArrayList<Float>();
public List<Float> getMyList(){
for(int i=0;i<10;i++)
integerList.add((int)((Float.parseFloat(i+""))+(1.11F)));
return (List)(Object)integerList;
}
public void testMethods(){
//...
}
}.getMyList();
for(int i=0;i<10;i++)
list.add((Float)(floatList.get(i)) * 11.232F * i);
return list;
}
}.getMyList();
}
}
</code>
---
The output of the code when compiled :
bash-2.05b$ $b/javac -Xlint Test13.java
Test13.java:18: warning: [serial] serializable class <anonymous Test13$1$1> has no definition of serialVersionUID
public void testMethods(){
^
1 warning
---
As testMethods is the last method of anonymous inner classes, compiler treats this as location of the [serial] warning.
If the all the methods and veriable are removed from the class then compiler will not give any line number.
Please see the following code:
<code>
import java.util.List;
import java.util.ArrayList;
public class Test13{
@SuppressWarnings("unchecked")
public void anonymousMethod(){
List list = new ArrayList<String>(){
static final long serialVersionUID = 1;
List list = new ArrayList<Integer>();
public List<Integer> getMyList(){
final List floatList = new ArrayList<Float>(){
// Blank ....
};
for(int i=0;i<10;i++)
list.add((Float)(floatList.get(i)) * 11.232F * i);
return list;
}
}.getMyList();
}
}
</code>
Output of the code when compiled:
bash-2.05b$ $b/javac -Xlint Test13.java
warning: [serial] serializable class <anonymous Test13$1$1> has no definition of serialVersionUID
1 warning
No line number for the warning..
--
###@###.### 2005-04-11 10:55:04 GMT
Compiler will fail to find the location of [serial] warnings for anonymous inner classes. It will always gives the last method or the last variable of the class as the location of warning, if the class is blank i.e. no methods or variables then compiler will not give any line number.
Please see the following code:
<code>
import java.util.List;
import java.util.ArrayList;
public class Test13{
@SuppressWarnings("unchecked")
public void anonymousMethod(){
List list = new ArrayList<String>(){
static final long serialVersionUID = 1;
List list = new ArrayList<Integer>();
public List<Integer> getMyList(){
final List floatList = new ArrayList<Float>(){
List integerList = new ArrayList<Float>();
public List<Float> getMyList(){
for(int i=0;i<10;i++)
integerList.add((int)((Float.parseFloat(i+""))+(1.11F)));
return (List)(Object)integerList;
}
public void testMethods(){
//...
}
}.getMyList();
for(int i=0;i<10;i++)
list.add((Float)(floatList.get(i)) * 11.232F * i);
return list;
}
}.getMyList();
}
}
</code>
---
The output of the code when compiled :
bash-2.05b$ $b/javac -Xlint Test13.java
Test13.java:18: warning: [serial] serializable class <anonymous Test13$1$1> has no definition of serialVersionUID
public void testMethods(){
^
1 warning
---
As testMethods is the last method of anonymous inner classes, compiler treats this as location of the [serial] warning.
If the all the methods and veriable are removed from the class then compiler will not give any line number.
Please see the following code:
<code>
import java.util.List;
import java.util.ArrayList;
public class Test13{
@SuppressWarnings("unchecked")
public void anonymousMethod(){
List list = new ArrayList<String>(){
static final long serialVersionUID = 1;
List list = new ArrayList<Integer>();
public List<Integer> getMyList(){
final List floatList = new ArrayList<Float>(){
// Blank ....
};
for(int i=0;i<10;i++)
list.add((Float)(floatList.get(i)) * 11.232F * i);
return list;
}
}.getMyList();
}
}
</code>
Output of the code when compiled:
bash-2.05b$ $b/javac -Xlint Test13.java
warning: [serial] serializable class <anonymous Test13$1$1> has no definition of serialVersionUID
1 warning
No line number for the warning..
--
###@###.### 2005-04-11 10:55:04 GMT
- duplicates
-
JDK-6322344 Compiler throws misleading error report when interface method implemented in anonymous inner class.
- Closed
-
JDK-6320556 Bad position for anonymous class
- Closed
- relates to
-
JDK-6267097 Compiler issuses [unchecked] warning without line number for anonymous inner classes.
- Closed
-
JDK-6264029 Compiler issues two diagnostics for anonymous class, one is sufficient
- Closed