ModuleInfo extends AnnotatedElement

Mandy Chung mandy.chung at oracle.com
Tue Apr 20 14:33:50 PDT 2010


The current API only supports to read annotations of a module when the 
module has been installed by using the java.lang.reflect.Module API 
(that extends AnnotatedElement).   There are cases that one would want 
to read the annotations from module-info while the module is being 
installed.  For example, a module can include some annotation to specify 
the installation requirement that can be used to determine if the module 
installation should continue based on the system configuration.  It is 
an opportunity to eliminate  transfers of the entire module and its 
dependencies if not needed.

We need to provide an API to read the annotations from module-info but 
the module may not be installed or downloaded at all.

One proposal is to extend java.lang.module.ModuleInfo to extend 
AnnotatedElement:
 
http://cr.openjdk.java.net/~mchung/jigsaw/annotations/api/java/lang/module/ModuleInfo.html

It will not load any classes referenced by annotations for this 
ModuleInfo until the getAnnotation or other method specified in the 
AnnotatedElement interface is called (since those classes might not 
exist or be found by the class loader).  In other word, this change will 
not affect the current module loading/resolution.   It will use the 
current module class loader to find classes to construct the Annotation 
objects.   If the type of an annotation's element cannot be found,  it 
will result in a TypeNotPresentException in the current proposed 
specification.  TypeNotPresentException is an unchecked exception and 
perhaps it'd be better to throw a checked exception.

Any comment, opinion?

Joe, your feedback would be helpful.

Thanks
Mandy



More information about the jigsaw-dev mailing list