javac accepts enums, annotations and final classes being referenced by 'uses' statement

Peter Levart peter.levart at gmail.com
Wed Mar 30 14:16:10 UTC 2016


Hi Georgiy,

 From the 3 cases below, I think only enum case is maybe problematic. 
And only because we know that no enum implementation class defines a 
public no-argument constructor. Final class is perfectly fine (it can be 
provided by its module with itself as the implementation class). 
Annotation interface has a history of being no exception in Java 
language for implementing by normal classes, so I would also not limit 
it here.

For enum case then perhaps the module descriptor could enlist an enum 
constant name instead of class name as the implementation. This could 
also be the alternative when specifying service implementations for 
interfaces. For example:

a/module-info.java:
     module a {
         uses pkg.Service;
     }

b/module-info.java:
     module b {
         exports pkg;
         provides pkg.Service with [instance?] pkg.impl.ServiceImpl.ONE;
     }

b/pkg/Service.java:
     package pkg;
     public interface Service {}

b/pkg/impl/ServiceImpl.java:
     package pkg.impl;
     public enum ServiceImpl implements Service { ONE }


Regards, Peter

On 03/30/2016 01:18 PM, Georgiy Rakov wrote:
> Hello,
>
> currently JDK9b111 javac successfully compiles following code:
>
>    a/module-info.java:
>    module a {
>         uses pkg.FinalClassST;
>         uses pkg.EnumST;
>         uses pkg.AnnotationST;
>    }
>
>    a/pkg/AnnotationST.java:
>    package pkg;
>    public @interface AnnotationST{}
>
>    a/pkg/EnumST.java:
>    package pkg;
>    public enum EnumST {A,B}
>
>    a/pkg/FinalClassST.java:
>    package pkg;
>    public final class FinalClassST{}
>
>
> Could you please tell if this is javac, spec or both issue that type 
> being referenced by 'uses' statement is not checked at compile-time 
> for ability to be a service interface.
>
> The minimized testcase is attached; in order to run it please:
> 1. unzip attached archive on Windows machine;
> 2. rename test9\test_bat to test9\test.bat;
> 3. modify test.bat by changing JDK_HOME variable to point to your JDK 
> installation;
> 4. run test.bat.
>
> BTW: provided the type name references non existing type javac does 
> produce compile error.
>
> Thanks,
> Georgiy.



More information about the jigsaw-dev mailing list