Skip to content

Cannot convert function to interface java.util.function.Consumer since it contains methods with different names #511

@GuillermoBlasco

Description

@GuillermoBlasco

Given an arrow function passed to a forEach the intepreter crashes with the message:

org.mozilla.javascript.EvaluatorException: Cannot convert function to interface java.util.function.Consumer since it contains methods with different names (<script name>#<line number>)

The point is that the InterfaceAdapter:27 expects an interface with at least one method, and if many all called the same. Which makes sense prior to default keyword for interfaces. But given that Consumer interface now has a andThen default method InterfaceAdapter:27 finds that there are two methods called differently.

Rhino version: 1.7.10

JS code interpreted:

tc.getValues().forEach(function (value) {
  if (value.get('XX').get() === 'xx') {
    if (value.get('YY') === undefined) {
        value.set('YY', new Date());   
    }
  }  
});

Where tc.getValues() returns a NativeArray.

Stack trace:

rg.mozilla.javascript.EvaluatorException: Cannot convert function to interface java.util.function.Consumer since it contains methods with different names (<script_name>#<line number>)
	at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:77) ~[rhino-1.7.10.jar:1.7.10]
	at org.mozilla.javascript.Context.reportRuntimeError(Context.java:998) ~[rhino-1.7.10.jar:1.7.10]
	at org.mozilla.javascript.Context.reportRuntimeError(Context.java:1053) ~[rhino-1.7.10.jar:1.7.10]
	at org.mozilla.javascript.Context.reportRuntimeError1(Context.java:1016) ~[rhino-1.7.10.jar:1.7.10]
	at org.mozilla.javascript.InterfaceAdapter.create(InterfaceAdapter.java:52) ~[rhino-1.7.10.jar:1.7.10]
	at org.mozilla.javascript.NativeJavaObject.createInterfaceAdapter(NativeJavaObject.java:681) ~[rhino-1.7.10.jar:1.7.10]
	at org.mozilla.javascript.NativeJavaObject.coerceTypeImpl(NativeJavaObject.java:657) ~[rhino-1.7.10.jar:1.7.10]
	at org.mozilla.javascript.Context.jsToJava(Context.java:1874) ~[rhino-1.7.10.jar:1.7.10]
	at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:191) ~[rhino-1.7.10.jar:1.7.10]
	at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:32) ~[rhino-1.7.10.jar:1.7.10]
	at org.mozilla.javascript.gen.<script_name>._c_script_0(<script_name>:<line numbe>) ~[na:na]
	at org.mozilla.javascript.gen.<script_name>.call(<script_name>) ~[na:na]
	at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:405) ~[rhino-1.7.10.jar:1.7.10]
	at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3508) ~[rhino-1.7.10.jar:1.7.10]
	at org.mozilla.javascript.gen.<script_name>.call(<script_name>) ~[na:na]
	at org.mozilla.javascript.gen.<script_name>.exec(<script_name>) ~[na:na]
	at org.mozilla.javascript.Context.evaluateString(Context.java:1262) ~[rhino-1.7.10.jar:1.7.10]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions