<p>I'm using ant to generate javadocs, but get this exception over and over - why?</p>

<p>I'm using JDK version <strong>1.6.0_06</strong>.</p>

<pre><code>[javadoc] java.lang.ClassCastException: com.sun.tools.javadoc.ClassDocImpl cannot be cast to com.sun.javadoc.AnnotationTypeDoc
  [javadoc]     at com.sun.tools.javadoc.AnnotationDescImpl.annotationType(AnnotationDescImpl.java:46)
  [javadoc]     at com.sun.tools.doclets.formats.html.HtmlDocletWriter.getAnnotations(HtmlDocletWriter.java:1739)
  [javadoc]     at com.sun.tools.doclets.formats.html.HtmlDocletWriter.writeAnnotationInfo(HtmlDocletWriter.java:1713)
  [javadoc]     at com.sun.tools.doclets.formats.html.HtmlDocletWriter.writeAnnotationInfo(HtmlDocletWriter.java:1702)
  [javadoc]     at com.sun.tools.doclets.formats.html.HtmlDocletWriter.writeAnnotationInfo(HtmlDocletWriter.java:1681)
  [javadoc]     at com.sun.tools.doclets.formats.html.FieldWriterImpl.writeSignature(FieldWriterImpl.java:130)
  [javadoc]     at com.sun.tools.doclets.internal.toolkit.builders.FieldBuilder.buildSignature(FieldBuilder.java:184)
  [javadoc]     at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)
  [javadoc]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  [javadoc]     at java.lang.reflect.Method.invoke(Method.java:597)
  [javadoc]     at com.sun.tools.doclets.internal.toolkit.builders.FieldBuilder.invokeMethod(FieldBuilder.java:114)
  [javadoc]     at com.sun.tools.doclets.internal.toolkit.builders.AbstractBuilder.build(AbstractBuilder.java:90)
  [javadoc]     at com.sun.tools.doclets.internal.toolkit.builders.AbstractMemberBuilder.build(AbstractMemberBuilder.java:56)
  [javadoc]     at com.sun.tools.doclets.internal.toolkit.builders.FieldBuilder.buildFieldDoc(FieldBuilder.java:158)
  [javadoc]     at sun.reflect.GeneratedMethodAccessor51.invoke(Unknown Source)
  [javadoc]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  [javadoc]     at java.lang.reflect.Method.invoke(Method.java:597)
  [javadoc]     at com.sun.tools.doclets.internal.toolkit.builders.FieldBuilder.invokeMethod(FieldBuilder.java:114)
  [javadoc]     at com.sun.tools.doclets.internal.toolkit.builders.AbstractBuilder.build(AbstractBuilder.java:90)
  [javadoc]     at com.sun.tools.doclets.internal.toolkit.builders.AbstractMemberBuilder.build(AbstractMemberBuilder.java:56)
  [javadoc]     at com.sun.tools.doclets.internal.toolkit.builders.ClassBuilder.buildFieldDetails(ClassBuilder.java:301)
  [javadoc]     at sun.reflect.GeneratedMethodAccessor43.invoke(Unknown Source)
  [javadoc]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  [javadoc]     at java.lang.reflect.Method.invoke(Method.java:597)
  [javadoc]     at com.sun.tools.doclets.internal.toolkit.builders.ClassBuilder.invokeMethod(ClassBuilder.java:101)
  [javadoc]     at com.sun.tools.doclets.internal.toolkit.builders.AbstractBuilder.build(AbstractBuilder.java:90)
  [javadoc]     at com.sun.tools.doclets.internal.toolkit.builders.ClassBuilder.buildClassDoc(ClassBuilder.java:124)
  [javadoc]     at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source)
  [javadoc]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  [javadoc]     at java.lang.reflect.Method.invoke(Method.java:597)
  [javadoc]     at com.sun.tools.doclets.internal.toolkit.builders.ClassBuilder.invokeMethod(ClassBuilder.java:101)
  [javadoc]     at com.sun.tools.doclets.internal.toolkit.builders.AbstractBuilder.build(AbstractBuilder.java:90)
  [javadoc]     at com.sun.tools.doclets.internal.toolkit.builders.ClassBuilder.build(ClassBuilder.java:108)
  [javadoc]     at com.sun.tools.doclets.formats.html.HtmlDoclet.generateClassFiles(HtmlDoclet.java:155)
  [javadoc]     at com.sun.tools.doclets.internal.toolkit.AbstractDoclet.generateClassFiles(AbstractDoclet.java:164)
  [javadoc]     at com.sun.tools.doclets.internal.toolkit.AbstractDoclet.startGeneration(AbstractDoclet.java:106)
  [javadoc]     at com.sun.tools.doclets.internal.toolkit.AbstractDoclet.start(AbstractDoclet.java:64)
  [javadoc]     at com.sun.tools.doclets.formats.html.HtmlDoclet.start(HtmlDoclet.java:42)
  [javadoc]     at com.sun.tools.doclets.standard.Standard.start(Standard.java:23)
  [javadoc]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  [javadoc]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  [javadoc]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  [javadoc]     at java.lang.reflect.Method.invoke(Method.java:597)
  [javadoc]     at com.sun.tools.javadoc.DocletInvoker.invoke(DocletInvoker.java:215)
  [javadoc]     at com.sun.tools.javadoc.DocletInvoker.start(DocletInvoker.java:91)
  [javadoc]     at com.sun.tools.javadoc.Start.parseAndExecute(Start.java:340)
  [javadoc]     at com.sun.tools.javadoc.Start.begin(Start.java:128)
  [javadoc]     at com.sun.tools.javadoc.Main.execute(Main.java:41)
  [javadoc]     at com.sun.tools.javadoc.Main.main(Main.java:31)
</code></pre>

[{'answer_id': 44870, 'author': 'John Meagher', 'author_id': 3535, 'author_profile': 'https://Stackoverflow.com/users/3535', 'pm_score': 7, 'selected': True, 'text': '<p>It looks like this has been reported as a <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6442982" rel="noreferrer">Java bug</a>.  It appears to be caused by using annotations from a 3rd party library (like JUnit) and not including the jar with that annotation in the javadoc invocation.  </p>\n\n<p>If that is the case, just use the -classpath option on javadoc and include the extra jar files.  </p>\n'}, {'answer_id': 2030179, 'author': 'KasthuriRengan', 'author_id': 246673, 'author_profile': 'https://Stackoverflow.com/users/246673', 'pm_score': 1, 'selected': False, 'text': "<p>I have some idea regarding this problem but this not exact solution to get.</p>\n<p>If you give single comment line <code>//</code> before annotation and try to run the javadoc once again. This problem will solve</p>\n<p>Eg: <code>sample.java</code> file</p>\n<pre><code>@ChannelPipeline\n</code></pre>\n<p>Makes changes in</p>\n<pre><code>//@ChannelPipeline\n</code></pre>\n<p>Try to run javadoc command once again. Now <code>ClassCastException</code> won't occur.</p>\n"}, {'answer_id': 23737003, 'author': 'Cataclysm', 'author_id': 1531064, 'author_profile': 'https://Stackoverflow.com/users/1531064', 'pm_score': 0, 'selected': False, 'text': '<p>I got this problem too. I can compile properly without any errors or warnings. But when I generating javadoc , I got below error.</p>\n\n<blockquote>\n  <p><strong><em>[javadoc] java.lang.ClassCastException: com.sun.tools.javadoc.ClassDocImpl cannot be cast to com.sun.javadoc.AnnotationTypeDoc</em></strong></p>\n</blockquote>\n\n<p>Here is my classpath loading for my third-party-libs ...</p>\n\n<pre><code>&lt;path id="build.classpath"&gt;\n&lt;fileset dir="."&gt;\n    &lt;include name="libs/*.jar" /&gt;\n&lt;/fileset&gt;\n</code></pre>\n\n<p></p>\n\n<p>At my java compile target ..</p>\n\n<pre><code>&lt;target name="compile" depends="clean, makedir"&gt;\n&lt;javac includeantruntime="false" srcdir="${src.dir}" destdir="${build.dir}" classpathref="build.classpath"&gt;\n  &lt;compilerarg value="-Xlint:unchecked"/&gt;\n&lt;/javac&gt;\n</code></pre>\n\n<p></p>\n\n<p>And at my javadoc target...</p>\n\n<pre><code>&lt;target name="docs" depends="compile"&gt;\n&lt;javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}" \n    failonerror="no"\n    author="true"\n    version="true"\n    windowtitle="${Name} API"\n    doctitle="${Name}"\n    bottom="Copyright © 2014 ColayHIlls.com . All Rights Reserved."&gt;\n   &lt;fileset dir="${src.dir}"&gt;\n            &lt;include name="main/java/com/colayhills/jpcenter/business/service/**" /&gt;\n   &lt;/fileset&gt;\n&lt;/javadoc&gt;\n&lt;echo message="java docs has been generated!"/&gt;\n&lt;/target&gt;\n</code></pre>\n\n<p>So , I added <code>classpathref="build.classpath"</code> option to <code>&lt;javadoc</code> tag. Now It is fine for me.</p>\n'}, {'answer_id': 40803470, 'author': 'Eduard Wirch', 'author_id': 17428, 'author_profile': 'https://Stackoverflow.com/users/17428', 'pm_score': 1, 'selected': False, 'text': '<p>There is another way to get a <code>ClassCastException</code> in versions of Java from 5 through 8:</p>\n<p><code>java.lang.ClassCastException: com.sun.tools.javadoc.MethodDocImpl cannot be cast to com.sun.tools.javadoc.AnnotationTypeElementDocImpl</code></p>\n<p>It will happen when javadoc encounters a reference to a annotation method in javadoc text before processing the same annotation for the first time used in code. Take these two classes:</p>\n<pre><code>/**\n ** {@link javax.annotation.Generated#value()}\n */\npublic class TestClass1 {}\n\n\n@Generated(&quot;sometext&quot;)\npublic class TestClass2 {}\n</code></pre>\n<p>The bug is order dependent. If javadoc processes <code>TestClass1</code> first, the <code>ClassCastException</code> will be thrown. If javadoc processes <code>TestClass2</code> first, it will complete fine. The bug is reported as <a href="http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8170447" rel="nofollow noreferrer">JDK-8170444</a>, and was resolved as &quot;Won\'t Fix&quot;.  The bug is no longer present in Java 9.</p>\n<p>As a workaround, don\'t link to annotation methods in your documentation text.</p>\n'}]
['https://Stackoverflow.com/questions/44853', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1310/']