Help

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

It's pretty likely that if you are getting this exception, then you are using the IBM JVM and the exception is triggered by a call to java.lang.Class.getDeclaredAnnotations. In that case, your stack trace likely ends in these lines (if not, this FAQ isn't going to help you much):

java.lang.TypeNotPresentException: Type [some annotation class] not present
	at com.ibm.oti.reflect.AnnotationHelper.getAnnotation(AnnotationHelper.java:38)
	at com.ibm.oti.reflect.AnnotationHelper.getDeclaredAnnotations(AnnotationHelper.java:50)
	at java.lang.Class.getDeclaredAnnotations(Class.java:1648)
	at java.lang.Class.getAnnotations(Class.java:1609)
	at java.lang.Class.getAnnotation(Class.java:1589)
	at java.lang.Class.isAnnotationPresent(Class.java:1676)

When executing on the IBM JVM, if a class is annotated with a type that is not available on the classpath and you invoke any of the annotation-related inspection methods on the Class object (i.e., getAnnotations(), getAnnotation(), isAnnotationPresent()), the JVM will throw this exception, even if you are not trying to access the unavailable type. For instance, you might be looking for the @Install annotation on a class. If the class is annotated with @Stateful and the EJB 3 API is not on the classpath, this exception is thrown.

Seam's core scanning process now calls the getAnnotations() method on a class immediately after loading it. This step ensures that the class is only considered loaded if the annotations can be accessed w/o exception. It's still possible to run into this exception if you declare a component (via XML) in the Seam component descriptor for a class that has an annotation which is not present on the classpath. In that case, the exception is warranted and you need to either disable the component or add the missing library.

It's interesting to note that the Sun JVM simply ignores any annotations which are not available on the classpath, as if they aren't even there. That's probably best since annotations are just metadata, but can be equally problematic if those annotations were supposed to enforce behavior. It would be best if the JVM threw an exception if you tried to access the missing type.