users@jaxb.java.net

"ClassTypeImpl cannot be cast to com.sun.mirror.type.AnnotationType" on schemagen

From: KARR, DAVID (ATTCINW) <"KARR,>
Date: Wed, 6 Jan 2010 15:17:14 -0800

I've been working on an app using CXF/JAXB/OpenJPA for a few weeks. I
had added the "schemagen" task work a while ago, and I was able to
generate the schema. Recently I tried doing it again, and I'm seeing
exceptions like the following:

------------------------
Generating schema from 48 source files
error: Could not create declaration for annotation type Strategy
error: Could not create declaration for annotation type OrderColumn
error: Could not create declaration for annotation type Temporal
error: Could not create declaration for annotation type OneToMany
error: Could not create declaration for annotation type Column
error: Could not create declaration for annotation type Basic
error: Could not create declaration for annotation type OneToOne
error: Could not create declaration for annotation type Id
error: Could not create declaration for annotation type IdClass
error: Could not create declaration for annotation type Entity
Problem encountered during annotation processing;
see stacktrace below for more information.
java.lang.ClassCastException:
com.sun.tools.apt.mirror.type.ClassTypeImpl cannot be cast to
com.sun.mirror.type.AnnotationType
        at
com.sun.tools.apt.mirror.declaration.AnnotationMirrorImpl.getAnnotationT
ype(AnnotationMirrorImpl.java:82)
        at
com.sun.tools.jxc.apt.InlineAnnotationReaderImpl.getAllAnnotations(Inlin
eAnnotationReaderImpl.java:113)
        at
com.sun.tools.jxc.apt.InlineAnnotationReaderImpl.getAllFieldAnnotations(
InlineAnnotationReaderImpl.java:88)
        at
com.sun.tools.jxc.apt.InlineAnnotationReaderImpl.getAllFieldAnnotations(
InlineAnnotationReaderImpl.java:64)
        at
com.sun.xml.bind.v2.model.impl.ClassInfoImpl.findFieldProperties(ClassIn
foImpl.java:371)
        at
com.sun.xml.bind.v2.model.impl.ClassInfoImpl.getProperties(ClassInfoImpl
.java:301)
        at
com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.ja
va:243)
        at
com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.ja
va:209)
        at
com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.jav
a:315)
        at
com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.jav
a:330)
        at
com.sun.tools.xjc.api.impl.j2s.JavaCompilerImpl.bind(JavaCompilerImpl.ja
va:90)
        at
com.sun.tools.jxc.apt.SchemaGenerator$1.process(SchemaGenerator.java:115
)
        at
com.sun.mirror.apt.AnnotationProcessors$CompositeAnnotationProcessor.pro
cess(AnnotationProcessors.java:60)
        at com.sun.tools.apt.comp.Apt.main(Apt.java:454)
        at
com.sun.tools.apt.main.JavaCompiler.compile(JavaCompiler.java:258)
        at com.sun.tools.apt.main.Main.compile(Main.java:1102)
        at com.sun.tools.apt.main.Main.compile(Main.java:964)
        at com.sun.tools.apt.Main.processing(Main.java:95)
        at com.sun.tools.apt.Main.process(Main.java:85)
        at com.sun.tools.apt.Main.process(Main.java:67)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
com.sun.tools.jxc.AptBasedTask$InternalAptAdapter.execute(AptBasedTask.j
ava:97)
        at com.sun.tools.jxc.AptBasedTask.compile(AptBasedTask.java:144)
        at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:882)
        at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
        at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:1
06)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:357)
        at org.apache.tools.ant.Target.performTasks(Target.java:385)
        at
org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
        at
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecut
or.java:41)
        at
org.apache.tools.ant.Project.executeTargets(Project.java:1189)
        at org.apache.tools.ant.Main.runBuild(Main.java:758)
        at org.apache.tools.ant.Main.startAnt(Main.java:217)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
-----------------

My domain classes that have the "@Xml..." annotations also have
JPA-related annotations on them (like "Entity", "Id", etc.).

I'm not having trouble compiling and executing this code, I'm just
unable to generate the schema.

From my searches, it appears that other people have run into this. In
fact, it appears to be the presence of the non-JAXB annotations that
causes this problem. It's not really practical to remove the non-JAXB
annotations.

Is there any other easier workaround for this problem?