[External] : Re: PreviewFeature on packages and modules
Alex Buckley
alex.buckley at oracle.com
Wed Feb 3 20:11:36 UTC 2021
On 2/3/2021 11:42 AM, Nikita Eshkeev wrote:
> I haven't seen https://bugs.openjdk.java.net/browse/JDK-8249554 , but
> I've been perusing JEP-12 https://openjdk.java.net/jeps/12 for quite
> some time now and it says the following about the modules:
>
> "To allow for intra-JDK use of a preview API, source code in the same
> module as a preview API is deemed to be "participating..."
>
> I can only guess that "intra-JDK" here means that the module is used by
> other modules inside the JDK, the JEP doesn't mention how modules that
> are introduced as preview API (annotated with PreviewFeature) is used
> outside the JDK.
JDK modules are relatively large and rich. It would be unfortunate if a
preview API in, say, java.base, couldn't be used elsewhere in java.base,
either in the implementation of a method within java.base or in the
public signature of some other exported API of java.base. (A flaw of
incubating APIs is that standard API signatures can't be enhanced to
accept and return classes of the incubating API. That limits exposure of
the incubating API, which means less feedback. Preview APIs, with their
greater claim to stability, appear in java.* packages and can thus
appear in standard API signatures.)
That's what the intra-JDK scenario is about -- use within the same
module. We might wish to expand the scenario in future, to allow use by
other JDK modules that have "some" relationship with the declaring
module, but that's not been shown to be necessary yet.
I'm not sure what you mean by "the JEP doesn't mention how modules that
are introduced as preview API is used outside the JDK". A preview API is
defined to include a module or a package, not just a class or interface,
so any use of an @PreviewFeature module by non-participating source code
should trigger the warning/error described in "Use of Preview Features".
Whether the non-participating source code is in some other java.*
module, or in some jdk.* module, or in some user module doesn't matter.
> The JEP mentions that the code that is inside a package that is
> introduced as preview API is considered as participating and doesn't
> generate compile-time errors/warning, so I conclude that javac hasn't
> implemented this part yet, but it should.
Right.
Alex
> 03.02.2021, 20:54, "Alex Buckley" <alex.buckley at oracle.com>:
>
> 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
> https://bugs.openjdk.java.net/browse/JDK-8249554
> <https://bugs.openjdk.java.net/browse/JDK-8249554> -- 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
> warnings/errors.
>
> I can't tell where your Main.java 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.
>
> Alex
>
> On 2/3/2021 8:00 AM, Nikita Eshkeev wrote:
>
> The PreviewFeature
> (https://github.com/openjdk/jdk/blob/master/src/java.base/sha…
> <https://urldefense.com/v3/__https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java__;!!GqivPVa7Brio!LxjKv9JdKyJ8GVP6bYd5mhzj4IQaifeEJOjjdwfCgrWzJ5_pgydVKDGFKjP3a0N-3Us$>
>
> <https://github.com/openjdk/jdk/blob/master/src/java.base/sha…
> <https://urldefense.com/v3/__https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java__;!!GqivPVa7Brio!LxjKv9JdKyJ8GVP6bYd5mhzj4IQaifeEJOjjdwfCgrWzJ5_pgydVKDGFKjP3a0N-3Us$>>)
>
> 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 module-info.java, package-info.java and
> MyPreviewClass.java
> (which is just an empty class)
> 3. I annotated both module-info.java and package-info.java with
> PreviewFeature
> 4. I exported jdk.internal.javac package to jdk.neshkeev in
> module-info.java of java.base
> 5. `make images` the jdk's source code
> 6. I created Main.java with the following content
> class Main {
> {
> new jdk.neshkeev.MyPreviewClass();
> }
> }
> 7. I compiled Main.java with my openjdk that was built in the
> step 5.
> Here is the link to my openjdk fork with the jdk.neshkeev module:
> https://github.com/neshkeev/jdk
> <https://urldefense.com/v3/__https://github.com/neshkeev/jdk__;!!GqivPVa7Brio!LxjKv9JdKyJ8GVP6bYd5mhzj4IQaifeEJOjjdwfCgrWzJ5_pgydVKDGFKjP3fmAa7N8$>
> <https://github.com/neshkeev/jdk
> <https://urldefense.com/v3/__https://github.com/neshkeev/jdk__;!!GqivPVa7Brio!LxjKv9JdKyJ8GVP6bYd5mhzj4IQaifeEJOjjdwfCgrWzJ5_pgydVKDGFKjP3fmAa7N8$>>
> 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 Main.java 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