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



    • Type: Sub-task
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:


      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) {
               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

          Issue Links



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