Small questions about @RequireOptionalModule

Mandy Chung mandy.chung at oracle.com
Mon Mar 26 16:24:37 PDT 2012


On 3/26/2012 3:41 PM, Alexey Fedorov wrote:
> Hello,
>
> I have small question about current state of Jigsaw implementation:
>
> Suppose we have the following code fragment:
>
>> class A {
>>     @RequireOptionalModule("absent.module")
>>     public void foo(){
>>         //do nothing
>>     }
>> }
>>
>> new A().foo();
>
> @RequireOptionalModule javadoc alludes that if module "absent.module" 
> is absent, this code throws ModuleNotPresentException, but it doesn't. 
> Is it a bug?

The annotation does not imply any runtime check.  Instead the annotated 
method is responsible for testing if the "absent.module" is present 
before calling any API exported by that module [1] - i.e. by calling 
A.requriesModulePresent("absent.module")

@RequireOptionalModule annotation is intended for developer tools such 
as javadoc and javac to determine the sources of optional dependencies 
and it's not used at runtime to check if the named module is present or 
not.  This annotation can be used to annotate functionality that 
requires an optional module (e.g. Properties.loadFromXML) and this would 
assist developer tools for example to detect if the caller of such 
functionality is missing the optional module dependency.

Mandy

[1] http://openjdk.java.net/projects/jigsaw/doc/topics/optional.html




More information about the jigsaw-dev mailing list