April 17th, 2007

AnnotationFormatError bei Verarbeitung Annotations

Posted by frank in Java, J2EE

Ich wollte soeben von einer Klasse das Vorhandensein einer Annotation prüfen.

Hierzu wie gewohnt folgender Code:

Class clazz = …
if (clazz.isAnnotationPresent(Stateless.class)) { … }

Danach bekam ich folgende Exception um die Ohren geschmissen:

java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class org.jboss.annotation.ejb.RemoteBinding.factory()
	at java.lang.reflect.Method.getDefaultValue(Method.java:709)
	at sun.reflect.annotation.AnnotationType.(AnnotationType.java:90)
	at sun.reflect.annotation.AnnotationType.getInstance(AnnotationType.java:64)
	at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:202)
	at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
	at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
	at java.lang.Class.initAnnotationsIfNecessary(Class.java:2998)
…

Nach langer Suche und anfänglicher Fehlinterpretation bin ich dank des Bugeintrages bei Java dahinter gekommen, dass einfach eine Klasse nicht zur Verfügung stand. Die Annotation RemoteBinding definiert eine Klasse als Default-Wert, die in dem Standardpaket vom JBoss nicht mit enthalten ist und daher im JUnit-Test zu Problemen führen kann. Nachdem die richtige Bibliothek mit im Klassenpfad aufgenommen wurde, funktioniert auch die Analyze wie erwartet.

No Responses to ' AnnotationFormatError bei Verarbeitung Annotations '

Subscribe to comments with RSS or TrackBack to ' AnnotationFormatError bei Verarbeitung Annotations '.

Leave a reply

:mrgreen: :neutral: :twisted: :shock: :smile: :???: :cool: :evil: :grin: :oops: :razz: :roll: :wink: :cry: :eek: :lol: :mad: :sad: