PreviewFeature on packages and modules

Alex Buckley alex.buckley at
Wed Feb 3 17:54:40 UTC 2021

It looks like your neshkeev/jdk repo was forked from openjdk/jdk very 
recently, so your compiler should have the latest support for preview 
APIs. That support is specified at -- when preview 
features are enabled/disabled, no warning/error is due if "The 
declaration where the use of a preview API element appears is within the 
same module as the declaration of the preview API element."  This rule 
reflects the JEP 12 policy you refer to, where source code in the same 
module as a preview API is deemed as "participating" and causes no 

I can't tell where your file lives at compile time, but 
presumably you are not accidentally placing it in the jdk.neshkeev 
module. Like you, I expect a warning/error for Main's reference to 
MyPreviewClass, since Main is not participating in your preview API.


On 2/3/2021 8:00 AM, Nikita Eshkeev wrote:
> The PreviewFeature 
> ( 
> <>) 
> annotation can be applied to modules and packages. But I don't get any 
> compile-time errors/warnings when I try to use code that is inside of 
> either a package or a module that is annotated with PreviewFeature.
> What I did
> 1. I added a new module to openjdk with the "jdk.neshkeev" name
> 2. I added, and 
> (which is just an empty class)
> 3. I annotated both and with 
> PreviewFeature
> 4. I exported jdk.internal.javac package to jdk.neshkeev in 
> of java.base
> 5. `make images` the jdk's source code
> 6. I created with the following content
> class Main {
>   {
>     new jdk.neshkeev.MyPreviewClass();
>   }
> }
> 7. I compiled with my openjdk that was built in the step 5.
> Here is the link to my openjdk fork with the jdk.neshkeev module: 
> <>
> What is expected
> Since MyPreviewClass is inside of the package that is annotated with 
> PreviewFeature and it is also inside of the module that is also 
> annotated with PreviewFeature I expect to get compile time 
> errors/warnings. I believe that compile-time errors/warnings should 
> arise since can't be considered as participating source code
> What happened
> No compile-time errors/warnings occurred
> Is this a bug?

More information about the compiler-dev mailing list