Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8293321

[lworld] substitutability test shall support value class with cyclic membership

XMLWordPrintable

      Supposing a value class with itself as a field.
      value class Node {
           Node node;
      }

      var n1 = new Node(null);
      var n2 = new Node(n1);

      n1 == n2;

      Results in StackOverFlowError trying to create/find a methodHandle to perform `equals`.

      | at PrimitiveObjectMethods.substitutableInvoker (PrimitiveObjectMethods.java:420)
      | at PrimitiveObjectMethods$MethodHandleBuilder.primitiveTypeEquals (PrimitiveObjectMethods.java:131)
      | at PrimitiveObjectMethods$1.computeValue (PrimitiveObjectMethods.java:428)
      | at PrimitiveObjectMethods$1.computeValue (PrimitiveObjectMethods.java:426)
      | at ClassValue.getFromHashMap (ClassValue.java:229)
      | at ClassValue.getFromBackup (ClassValue.java:211)
      | at ClassValue.get (ClassValue.java:117)


      If embedding were intended, this would be clearly illegal and should result in a compile time error; but in this case the field is a reference to a Node.

            mchung Mandy Chung (Inactive)
            rriggs Roger Riggs
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: