Name: rmT116609 Date: 05/05/2004
FULL PRODUCT VERSION :
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP ver 2002 (Service Pack 1)
A DESCRIPTION OF THE PROBLEM :
The code segment provided below compiles without problems, but it produces a runtime error.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the class.
ACTUAL -
Compilation is fine, but the execution produces an error, and execution is aborted.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.VerifyError: (class: Fallo, method: main signature: ([Ljava/lang/String;)V) Incompatible argument to function
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.*;
public class Fallo {
public static void main(String [] args) {
List<String> lista = new ArrayList<String>();
lista.add("hola");
String s = (String)(lista.get(0));
System.out.println (s);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The problem is produced by the "unnecessay" brackets in the casting
for lista.get(0) combined with the casting and the later usage of the variable s.
Thus, if casting is not made, and the remaning code is maintained, then the problem (of course) is not produced.
If the variable "s" is not used after the casting, the problem does not appear.
And, if the unnecesary brackets are avoided, then the problem neither is raised.
So, we think the problem is motivated by the usage of unnecesary brackets in combination with a casting over generics.
(Incident Review ID: 261056)
======================================================================
- duplicates
-
JDK-5035001 redundant cast with generified APIs causes verify error
- Resolved