Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting a ClassCastException when generating javadocs?

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

I'm using JDK version 1.6.0_06.

[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) 
like image 454
ScArcher2 Avatar asked Sep 04 '08 21:09

ScArcher2


People also ask

What causes a ClassCastException?

ClassCastException is a runtime exception raised in Java when we try to improperly cast a class from one type to another. It's thrown to indicate that the code has attempted to cast an object to a related class, but of which it is not an instance.

How do you avoid ClassCastException in your code?

To prevent the ClassCastException exception, one should be careful when casting objects to a specific class or interface and ensure that the target type is a child of the source type, and that the actual object is an instance of that type.

What code will cause a ClassCastException to be thrown?

Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance. So, for example, when one tries to cast an Integer to a String , String is not an subclass of Integer , so a ClassCastException will be thrown. Object i = Integer.

Can we catch ClassCastException?

What you can do is pass in an instance of the Class of the parameterised type (assuming it isn't generic). class MyReader<T> { private final Class<T> clazz; MyReader(Class<T> clazz) { if (clazz == null) { throw new NullPointerException(); } this. clazz = clazz; } public T restore(String from) { ...


2 Answers

It looks like this has been reported as a Java bug. 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.

If that is the case, just use the -classpath option on javadoc and include the extra jar files.

like image 98
John Meagher Avatar answered Sep 23 '22 08:09

John Meagher


I have some idea regarding this problem but this not exact solution to get.

If you give single comment line // before annotation and try to run the javadoc once again. This problem will solve

Eg: sample.java file

@ChannelPipeline 

Makes changes in

//@ChannelPipeline 

Try to run javadoc command once again. Now ClassCastException won't occur.

like image 24
KasthuriRengan Avatar answered Sep 23 '22 08:09

KasthuriRengan