JDK-8157819 : TypeError when a java.util.Comparator object is invoked as a function
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2016-05-25
  • Updated: 2016-10-13
  • Resolved: 2016-05-25
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
8u112Fixed 9 b121Fixed
Nashorn supports calling FunctionalInterface interface objects to be treated like functions. This fails for java.util.Comparator objects:

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