Can't yield from within an instance created by reflection

Alan Bateman Alan.Bateman at oracle.com
Tue Apr 6 12:55:20 UTC 2021


On 06/04/2021 12:51, Øystein Myhre Andersen wrote:
> From: Øystein Myhre Andersen.
>
> Can't yield from within an instance created by reflection
>
> Is it meant to be like that, or will it be changed in the future?
>
> The following code sample illustrates the problem:
>
> class PinnedError {
>     static final ContinuationScope scope=new ContinuationScope("TST");
>
>     public PinnedError(String id) {
>        Continuation.yield(scope);
>     }
>
>     public static void main(String[] args) {
>        Continuation cont=new Continuation(scope,new Runnable() {
>           public void run() {
>              try {
>                 Constructor<PinnedError> constr =
> PinnedError.class.getConstructor(new Class[] { String.class });
>                 constr.newInstance("Name");
>              } catch (Exception e) { e.printStackTrace(); }
>        }});
>
>        cont.run();
>     }
> }

Just to add to Rémi's comments, this isn't an issue when using virtual 
threads. It's only an issue when using the Continuation API directly 
from a platform thread. The plan is to make this JDK internal soon, it's 
not meant to be exposed.

-Alan


More information about the loom-dev mailing list