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

Specialized functions convert booleans to numbers

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b148
    • CPU:
      generic
    • OS:
      generic

      Description

      Because the boolean type is considered narrower than numeric types in Nashorn it is possible to invoke builtin specialized functions that accept numeric params with boolean arguments. In many cases this leads to the correct result as arguments are converted to numbers anyway, but in the case of Array.prototype.concat and Array.prototype.push the result is wrong.

      var array = [].concat(true); // array is [1], should be [true]
      array.push(false); // array is [1, 0], should be [true, false]

      This only occurs with optimistic types enabled.

        Attachments

          Activity

            People

            • Assignee:
              hannesw Hannes Wallnoefer
              Reporter:
              hannesw Hannes Wallnoefer
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: