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

Array and List conversion, round 2

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 8
    • None
    • core-libs
    • None
    • b113
    • generic
    • generic

    Description

      JDK-8026113 introduced automatic conversion to Java arrays and lists. There are few odds and ends that need to be addressed, though:

      - There's now an overloaded method ambiguity when selecting between e.g. String and String[]. We solve it by having a preference for arrays when we are converting a native array. More precisely, we need to have a preference for List and Deque, and then for arrays.

      - We were getting a warning from Guards.isInstance linking that in some cases we were creating a test that always evaluates to false. It needs an adjustment in Dynalink's SimpleDynamicMethod when it's linking variable arity methods and there's exactly one argument for the vararg position. There, Dynalink has to decide whether to treat that last argument as being the vararg array itself, or as being the single element of the vararg array.

      Now, this particular issue (vararg special case with 1 argument in vararg array position) has some deeper implications in conjunction with automatic array conversions in Nashorn. Namely, what to do when a NativeArray is passed as a parameter here? Currently, Dynalink doesn't use language-specific conversions when considering this parameter. It *could*, but then since we can now convert *any* JS object to a Java array, we'd end up converting any object passed there to an array - even functions.

      Possible approaches here are:
      - leave it as it is. Passing a single NativeArray in the vararg array parameter position will still require explicit Java.to().

      - let Dynalink apply language-specific conversions to the values in the vararg array parameter position. In this case, however, we'll have to narrow down the automatic conversion to arrays to only apply to NativeArray class and nothing else. This actually seems reasonable (array-like objects that aren't actual arrays won't be automatically converted in any position anymore, but NativeArrays in vararg parameter position will). If we wouldn't narrow the automatic conversion to NativeArray only, then we'd be in for nasty surprise e.g. in test/script/basic/JDK-8008197.js:53 where the single passed function would be converted to an array…

      Attachments

        Issue Links

          Activity

            People

              attila Attila Szegedi
              attila Attila Szegedi
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: