I think https://bugs.openjdk.java.net/browse/JDK-8199149 is the relevant RFE.

Mandy

On 12/12/20 8:07 AM, Remi Forax wrote:
A student of mine send me a code that can be reduced to this code
---
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;

public class ThereIsABugButWhere {
   private static final VarHandle TEXT;
   static {
     try {
       TEXT = MethodHandles.lookup().findVarHandle(ThereIsABugButWhere.class, 
"text", String.class);
     } catch (NoSuchFieldException | IllegalAccessException e) {
       throw new AssertionError(e);
     }
   }


   private final String text;

   ThereIsABugButWhere() {
     text = "FOO";
   }

   public void update(String s) {
     TEXT.compareAndSet(this, "FOO", s);
   }

   public static void main(String[] args) {
     new ThereIsABugButWhere().update("BAR");
   }
}

---
If you execute it, you get
Exception in thread "main" java.lang.UnsupportedOperationException
        at java.base/java.lang.invoke.VarForm.getMemberName(VarForm.java:99)
        at 
java.base/java.lang.invoke.VarHandleGuards.guard_LLL_Z(VarHandleGuards.java:77)
        at ThereIsABugButWhere.update(ThereIsABugButWhere.java:22)
        at ThereIsABugButWhere.main(ThereIsABugButWhere.java:26)

It takes me 20 mins to find the issue ...
I think we can improve the error message or even better report the issue at the 
right location :)

regards,
Rémi

Reply via email to