JDK-6499662 : "java.lang.ClassCastException: cannot be cast to java.lang.String" happens from time to time
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-12-01
  • Updated: 2011-01-19
  • Resolved: 2006-12-21
Related Reports
Relates :  
Description
At my home system:
WinXP professional, ServicePack2
AMD Athlon 64

When using JavaCompiler.CompilationTask with preset annotation processor I randomly get ClassCastException.
It's being thrown from different places:

1) An exception has occurred in the compiler (1.6.0-rc). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport)  after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.
java.lang.ClassCastException:  cannot be cast to java.lang.String
	at com.sun.tools.javac.util.DefaultFileManager.listDirectory(DefaultFileManager.java:292)
	at com.sun.tools.javac.util.DefaultFileManager.list(DefaultFileManager.java:768)
	at com.sun.tools.javac.jvm.ClassReader.fillIn(ClassReader.java:2072)
	at com.sun.tools.javac.jvm.ClassReader.complete(ClassReader.java:1778)
	at com.sun.tools.javac.code.Symbol.complete(Symbol.java:386)
	at com.sun.tools.javac.code.Symbol$PackageSymbol.members(Symbol.java:596)
	at com.sun.tools.javac.comp.MemberEnter.importAll(MemberEnter.java:119)
	at com.sun.tools.javac.comp.MemberEnter.visitTopLevel(MemberEnter.java:509)
	at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:446)
	at com.sun.tools.javac.comp.MemberEnter.memberEnter(MemberEnter.java:387)
	at com.sun.tools.javac.comp.MemberEnter.complete(MemberEnter.java:819)
	at com.sun.tools.javac.code.Symbol.complete(Symbol.java:386)
	at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:758)
	at com.sun.tools.javac.comp.Enter.complete(Enter.java:451)
	at com.sun.tools.javac.comp.Enter.main(Enter.java:429)
	at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:819)
	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727)
	at com.sun.tools.javac.main.Main.compile(Main.java:353)
	at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:115)

2) An exception has occurred in the compiler (1.6.0-rc). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport)  after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.
java.lang.ClassCastException:  cannot be cast to java.lang.String
	at com.sun.tools.javac.util.DefaultFileManager.listDirectory(DefaultFileManager.java:292)
	at com.sun.tools.javac.util.DefaultFileManager.list(DefaultFileManager.java:768)
	at com.sun.tools.javac.jvm.ClassReader.fillIn(ClassReader.java:2072)
	at com.sun.tools.javac.jvm.ClassReader.complete(ClassReader.java:1778)
	at com.sun.tools.javac.code.Symbol.complete(Symbol.java:386)
	at com.sun.tools.javac.jvm.ClassReader.completeOwners(ClassReader.java:1790)
	at com.sun.tools.javac.jvm.ClassReader.complete(ClassReader.java:1769)
	at com.sun.tools.javac.code.Symbol.complete(Symbol.java:386)
	at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:758)
	at com.sun.tools.javac.code.Type$ClassType.complete(Type.java:687)
	at com.sun.tools.javac.code.Type$ClassType.getTypeArguments(Type.java:621)
	at com.sun.tools.javac.code.Type$ClassType.isErroneous(Type.java:644)
	at com.sun.tools.javac.comp.Check.checkNonCyclicInternal(Check.java:1469)
	at com.sun.tools.javac.comp.Check.checkNonCyclicInternal(Check.java:1480)
	at com.sun.tools.javac.comp.Check.checkNonCyclicInternal(Check.java:1480)
	at com.sun.tools.javac.comp.Check.checkNonCyclic(Check.java:1451)
	at com.sun.tools.javac.comp.Attr.attribBase(Attr.java:497)
	at com.sun.tools.javac.comp.MemberEnter.complete(MemberEnter.java:833)
	at com.sun.tools.javac.code.Symbol.complete(Symbol.java:386)
	at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:758)
	at com.sun.tools.javac.comp.Enter.complete(Enter.java:451)
	at com.sun.tools.javac.comp.Enter.main(Enter.java:429)
	at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:819)
	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727)
	at com.sun.tools.javac.main.Main.compile(Main.java:353)
	at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:115)
I've received this CCException again, now from java compiler launched with my IDE 

An exception has occurred in the compiler (1.6.0-rc). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport)  after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.
java.lang.ClassCastException:  cannot be cast to java.lang.String
	at com.sun.tools.javac.util.DefaultFileManager.listDirectory(DefaultFileManager.java:292)
	at com.sun.tools.javac.util.DefaultFileManager.list(DefaultFileManager.java:768)
	at com.sun.tools.javac.jvm.ClassReader.fillIn(ClassReader.java:2072)
	at com.sun.tools.javac.jvm.ClassReader.complete(ClassReader.java:1778)
	at com.sun.tools.javac.code.Symbol.complete(Symbol.java:386)
	at com.sun.tools.javac.code.Symbol$PackageSymbol.flags(Symbol.java:601)
	at com.sun.tools.javac.comp.Attr.checkId(Attr.java:2117)
	at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:1896)
	at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1522)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:360)
	at com.sun.tools.javac.comp.MemberEnter.visitImport(MemberEnter.java:527)
	at com.sun.tools.javac.tree.JCTree$JCImport.accept(JCTree.java:495)
	at com.sun.tools.javac.comp.MemberEnter.memberEnter(MemberEnter.java:387)
	at com.sun.tools.javac.comp.MemberEnter.memberEnter(MemberEnter.java:399)
	at com.sun.tools.javac.comp.MemberEnter.visitTopLevel(MemberEnter.java:512)
	at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:446)
	at com.sun.tools.javac.comp.MemberEnter.complete(MemberEnter.java:819)
	at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:758)
	at com.sun.tools.javac.code.Symbol$ClassSymbol.flags(Symbol.java:690)
	at com.sun.tools.javac.comp.Resolve.isAccessible(Resolve.java:124)
	at com.sun.tools.javac.comp.Resolve.loadClass(Resolve.java:843)
	at com.sun.tools.javac.comp.Resolve.findIdentInPackage(Resolve.java:1011)
	at com.sun.tools.javac.comp.Attr.selectSym(Attr.java:1918)
	at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:1832)
	at com.sun.tools.javac.comp.Enter.complete(Enter.java:451)
	at com.sun.tools.javac.comp.Enter.main(Enter.java:429)
	at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:819)
	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727)
	at com.sun.tools.javac.main.Main.compile(Main.java:353)
	at com.sun.tools.javac.main.Main.compile(Main.java:279)
	at com.sun.tools.javac.main.Main.compile(Main.java:270)
	at com.sun.tools.javac.Main.compile(Main.java:69)
	at com.sun.tools.javac.Main.main(Main.java:54)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
Compilation completed with 1 error and 0 warnings
1 error
0 warnings
Error:Compiler internal error. Process terminated with exit code 4

Comments
EVALUATION So i looked at the dump a bit using WinDbg and the SA and I'm suspecting there's something wrong with the machine. From the dumps for 828 and 1316. We die at 0x6d84b4c7 below. jvm!DefNewGeneration::copy_to_survivor_space: 6d84b480 51 push ecx 6d84b481 53 push ebx 6d84b482 55 push ebp 6d84b483 8b6c2410 mov ebp,dword ptr [esp+10h] 6d84b487 8b4504 mov eax,dword ptr [ebp+4] 6d84b48a 56 push esi 6d84b48b 8b700c mov esi,dword ptr [eax+0Ch] 6d84b48e 83c008 add eax,8 6d84b491 85f6 test esi,esi 6d84b493 57 push edi 6d84b494 8bf9 mov edi,ecx 6d84b496 897c2410 mov dword ptr [esp+10h],edi 6d84b49a 89742418 mov dword ptr [esp+18h],esi 6d84b49e 7f32 jg jvm!DefNewGeneration::copy_to_survivor_space+0x52 (6d84b4d2) 6d84b4a0 7d20 jge jvm!DefNewGeneration::copy_to_survivor_space+0x42 (6d84b4c2) 6d84b4a2 8b5508 mov edx,dword ptr [ebp+8] 6d84b4a5 8b407c mov eax,dword ptr [eax+7Ch] 6d84b4a8 83c9ff or ecx,0FFFFFFFFh 6d84b4ab 2bce sub ecx,esi 6d84b4ad d3e2 shl edx,cl 6d84b4af 8d4c0207 lea ecx,[edx+eax+7] 6d84b4b3 c1e902 shr ecx,2 6d84b4b6 81e1feffff3f and ecx,3FFFFFFEh 6d84b4bc 894c2418 mov dword ptr [esp+18h],ecx 6d84b4c0 eb0c jmp jvm!DefNewGeneration::copy_to_survivor_space+0x4e (6d84b4ce) 6d84b4c2 8b10 mov edx,dword ptr [eax] 6d84b4c4 55 push ebp 6d84b4c5 8bc8 mov ecx,eax 6d84b4c7 ff5250 call dword ptr [edx+50h] EAX=0x2b360a48, EBX=0x231432f0, ECX=0x2b360a48, EDX=0x00000000 ESP=0x02b7f980, EBP=0x229e14f0, ESI=0x00000000, EDI=0x002981c8 EIP=0x6d84b4c7, EFLAGS=0x00010246 So edx is supposed to be the vtable of an instanceKlass because we're calling instanceKlass::oop_size. edx came from [eax] which should be a Klass* which came from adding 8 to [ebp+4]. Looking at the dump [ebp+4] contains 0x2b160a40 which means eax should contain 0x2b160a40+8 == 0x2b160a48 but eax contains 0x2b360a48 which strangely is almost the same number but for a single bit difference. 0x2b360a48 doesn't point at an oop at all and the heap doesn't contain the value at all either. 0x2b160a48 is the klass pointer for java.lang.String which with sharing enabled will never move so it's not even possible that it's a stale oop reference. from the dump for 3064. It dies while walking the heap for full mark sweep collection. It dies processing an oop at 0x2346d168. Looking at the oop it's supposed to be a String but the class pointer looks funny. It's 0x2b170a40 but the real String klass pointer is 0x2b160a40 which is again a single bit difference. from 3004. The Reference Handler thread is dying while looking at java.lang.ref.Reference.pending which is a bad oop. It's 0x23288030 which is actually outside the allocated space of tenured. tenured generation total 4096K, used 696K [0x22e40000, 0x23240000, 0x26960000) I can't explain this at all. In the other dump we die processing a Finalizer because the referent is a bad oop. The value of the referent is a pointer into unallocated space in tenured but I can't tell whether the heap shrunk which made it bad or whether it was just invalid. So if there's something wrong with the machine then pretty much anything could be going wrong. Are you doing anything strange with the machine like underclocking it or could you turn off the power management in the core? The first three crashes really look like something is wrong with the machine.
20-12-2006