-
Notifications
You must be signed in to change notification settings - Fork 194
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
"Multiple applicable overloads found" when it's not the case #286
Comments
Hi @shavitush thanks for your report. I have tried to reproduce your failure, but have not managed to. For me it works in all setups I have tried. I know that we had similar issues before, and cannot rule out that we still have them. Can you share "full" working example of your code, because the details seem to matter here. BTW, in your example you have a deviation between upper and lower case My working example is as follows: test.js:
Main.java:
User.java:
|
@wirthi You are missing Nashorn compatibility mode. The described problem seems to be related to the Unfortunately, I have no idea how to solve this issue. The mentioned target mapping (from |
Thanks @iamstolis I missed that line in the text. So, @shavitush , have you tried running outside Nashorn-compatibility mode? What usecase do you have that requires to set the Nashorn compatibility - it might be easier to solve or work around that problem. Best, |
@shavitush, does the workaround found by @wirthi accidentally work in your case, i.e., does the rest of your application works when you invoke
during the initialization of |
I encountered the same mistake Multiple applicable overloads found
Java Code public void info(String msg) {
Object[] args = new Object[]{};
info(msg, args);
}
public void info(String format, Object arg) {
Object[] args = new Object[]{arg};
info(format, args);
}
public void info(String format, Object arg1, Object arg2) {
Object[] args = new Object[]{arg1, arg2};
info(format, args);
}
public void info(String msg, Throwable t) {
Object[] args = new Object[]{t};
info(msg, args);
}
/**
* info打印输出
*
* @param args 输出数据
*/
public void info(String format, Object... args) {
if (logger.isInfoEnabled()) {
TupleTow<String, Throwable> tupleTow = logString(format, args);
if (tupleTow.getValue2() == null) {
logger.info(tupleTow.getValue1());
} else {
logger.info(tupleTow.getValue1(), tupleTow.getValue2());
}
}
} JavaScript Code
|
因为 JavaScript 最上面的例子: JavaScript function start(user)
{
user.print(1, 3); // 这样没有问题
user.print(1, undefined); // 这里有问题! fixme, undefined -> null
} Java class User
{
public void Print(int n1, Integer n2) { System.out.println(String.format("%d %d", n1, n2)); }
public void Print(int n1, String n2) { System.out.println(String.format("%d %s", n1, n2)); }
} |
Hello, as a part of the migration process from Nashorn, I am trying to solve the problem with the automatic type conversions that Nashorn provided. We have quite extensive amount of methods available through bindings, and the conversion rules defined in the HostAccess builder looked promising. I intended to use it for the Boolean <-> String <-> Number conversions. However, there is the "Multiple applicable overloads" problem for every sourceType and targetType pair, when there is an overloaded method accepting both of these - for example Integer Java class constructor accepting String and int:
When run like this, line 3 of the script fails. When I uncomment the Object -> String targetTypeMapping, line 2 of the script fails (both with the What is the recommended procedure of handling the Nashorn - Graal migration regarding this issue? The only option I could think of is replacing the parameter types of all the Bindings' methods to Value and parse it myself. Is there a plan to fix this issue in the future? |
The latest development builds (and the soon to be released GraalVM 20.3) allow you to specify the priority/precedence of the target type mappings. So, your test-case works there if you lower the precedence of some of your mappings. For example, you can use
|
GraalVM 20.3 has been released. As @iamstolis described in the previous message, you can now specify the precedence of targetTypeMappings. I am closing this ticket. If you still cannot make your code work based on GraalVM 20.3 and precedences set properly, please open a new ticket with a short reproducer so we can investigate, thanks. |
This exception seems very wrong to me. I use
ScriptEngine
for the project with Nashorn compatibility mode. The exception message even says that I provided 2 integers and that one of the candidates accepts that for the arguments.JS code:
Java:
I run OpenJDK 14 with graal.js from Maven.
With my testing, this code works fine with version 19.0.0 of
org.graalvm.js.js
andorg.graalvm.js.js-scriptengine
, but not on 19.3.2 or 20.0.0The text was updated successfully, but these errors were encountered: