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

TypeError when a java.util.Comparator object is invoked as a function

    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:
      b121
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        Nashorn supports calling FunctionalInterface interface objects to be treated like functions. This fails for java.util.Comparator objects:

        jjs> f = java.util.Comparator.reverseOrder()
        java.util.Collections$ReverseComparator@6283d8b8
        jjs> f.compare(343, 55)
        -1
        jjs> f(343, 55)
        <shell>:1 TypeError: java.util.Collections$ReverseComparator@6283d8b8 has no suc
        h function "equals"

          Activity

          Hide
          sundar Sundararajan Athijegannathan added a comment -
          Interfaces annotated with @FunctionalInterface are expected to have a single abstract method and possibly many non-abstract (default, private) methods. But, such interfaces may redeclare methods of java.lang.Object (java.util.Comparator redeclares java.lang.Object's equals method). Such methods should not be taken to be that single-abstract-method. Nashorn locates first abstract method and considers that as the single-abstract-method of the functional interface. Redeclared java.lang.Object methods (in Comparator's case "equals" method) should be skipped.
          Show
          sundar Sundararajan Athijegannathan added a comment - Interfaces annotated with @FunctionalInterface are expected to have a single abstract method and possibly many non-abstract (default, private) methods. But, such interfaces may redeclare methods of java.lang.Object (java.util.Comparator redeclares java.lang.Object's equals method). Such methods should not be taken to be that single-abstract-method. Nashorn locates first abstract method and considers that as the single-abstract-method of the functional interface. Redeclared java.lang.Object methods (in Comparator's case "equals" method) should be skipped.
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/dev/nashorn/rev/59d31c4e3f77
          User: sundar
          Date: 2016-05-25 13:56:11 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/nashorn/rev/59d31c4e3f77 User: sundar Date: 2016-05-25 13:56:11 +0000
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/jdk9/nashorn/rev/59d31c4e3f77
          User: lana
          Date: 2016-06-01 18:59:18 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/nashorn/rev/59d31c4e3f77 User: lana Date: 2016-06-01 18:59:18 +0000

            People

            • Assignee:
              sundar Sundararajan Athijegannathan
              Reporter:
              sundar Sundararajan Athijegannathan
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: