Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8151179 address issues raised by JCK team on JEP 274 API
  3. JDK-8150964

j.l.i.MethodHandles.whileLoop(...) small documentation issues

XMLWordPrintable

    • Icon: Sub-task Sub-task
    • Resolution: Fixed
    • Icon: P4 P4
    • None
    • 9
    • core-libs

      Please, observe j.l.i.MethodHandles.whileLoop(...) sections:

      1. Returns: the value of the loop variable as the loop terminates.
      This could mislead users because actually this method returns method handle representing loop. But this information is necessary to, I suppose it could be good to store this assertion somewhere in documentation.
      2. Throws: IllegalArgumentException - if any argument has a type inconsistent with the loop structure
      It looks a little bit unclear, because there is no definition for 'loop structure'.
      3. The pred handle must have an additional leading parameter of the same type as init's result, and so must the body.
      -- It looks a little bit unclear, it's hard to understand what kind of parameters should 'pred' and body' have. It's clear that leading parameter is the same as 'init' return type, but there is no rules for other parameters. It could be deducted from pseudocode, but maybe it would be good to make this description clearer.
      -- The parameter list of resulting method handle could be deducted from pseudocode too, but it couldn't be determined from preceeding documentation.
      4. The implementation of this method is equivalent to:
       MethodHandle whileLoop(MethodHandle init, MethodHandle pred, MethodHandle body) {
           MethodHandle[]
               checkExit = {null, null, pred, identity(init.type().returnType())},
               varBody = {init, body};
           return loop(checkExit, varBody);
       }


      I suppose we can't say they are equals because according to doc, 'init'=null should work correctly, but according to given documentation, 'init'=null will lead to NullPointerException (see init.type()). So same calls with init==null for jdk implementation and for given implementation have different results. Example attached.

        1. InitNullImpl.java
          2 kB
        2. WhileLoopExample3.java
          1 kB
        3. WhileLoopProposal0.java
          2 kB
        4. WhileLoopProposal1.java
          3 kB
        5. WhileLoopProposal2.java
          4 kB
        6. WhileLoopProposal5.java
          3 kB
        7. WL.java
          3 kB

            mhaupt Michael Haupt
            asolodkaya Anastasiya Solodkaya (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: