Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
GuillermoBlasco opened this issue Jan 10, 2019 · 3 comments

Comments

@GuillermoBlasco
Copy link

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]
GuillermoBlasco added a commit to GuillermoBlasco/rhino that referenced this issue Jan 10, 2019
Now default methods are ignored, so they do not conflict with
interface (abstract) methods to implement.
rPraml added a commit to FOCONIS/rhino that referenced this issue Dec 10, 2019
@elie-g
Copy link

elie-g commented Jul 30, 2020

Is there any workaround?

@tonygermano
Copy link
Contributor

Suggest closing as implemented by #631

@p-bakker
Copy link
Collaborator

Closing as implemented by #631

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants