Closed
Bug 255549
Opened 21 years ago
Closed 21 years ago
JVM-dependent resolution of ambiguity when calling Java methods
Categories
(Rhino Graveyard :: Core, defect)
Tracking
(Not tracked)
VERIFIED
FIXED
1.6R1
People
(Reporter: igor, Assigned: igor)
Details
Attachments
(1 file, 1 obsolete file)
|
11.73 KB,
patch
|
Details | Diff | Splinter Review |
As of 2004-08-13 when calling overloaded Java methods Rhino does not implement
proper ambiguity resolution as specified by LC3 specs,
http://www.mozilla.org/js/liveconnect/lc3_method_overloading.html .
Consider the following Java class which is based on example provided by Merten
Schumann:
public class X
{
public static class Order1
{
public static int test(String[] array1, String[] array2, String s)
{
return 1;
}
public static int test(String s1, String s2, String s)
{
return 2;
}
}
public static class Order2
{
public static int test(String s1, String s2, String s)
{
return 2;
}
public static int test(String[] array1, String[] array2, String s)
{
return 1;
}
}
}
According to LC3 the following calls
Packages.X.Order1.test("x", null, null)
Packages.X.Order2.test("x", null, null)
should call test(String, String, String) of X.Order1 or X.Order2 correspondingly
since test(String[], String[], String) is not applicable. But depending on
compiler and JVM in Rhino either the first line or the second line produces:
js: "test.js", line 1: The choice of Java constructor test matching JavaScript
argument types (string,null,null) is ambiguous; candidate constructors are: int
test(java.lang.String[],java.lang.String[],java.lang.String), int
test(java.lang.String,java.lang.String,java.lang.String)
| Assignee | ||
Comment 1•21 years ago
|
||
The reason for the bug is that NativeJavaMethod.findFunction tested the method
applicability only if the search loop did not see any ambiguity yet. After that
it would check methods only against ambiguity. Thus if JVM returns for X.Other
classes:
test(String[],String[],String)
test(String,String,String)
then code will reject the first as inapplicable and choose the second case. If
the order would be
test(String,String,String)
test(String[],String[],String)
then code will picks up first method as applicable and then see ambiguity when
calling second and report error.
The patch fixes that and changes loop to track all currently best fitted
methods instead of doing a separated search after.
| Assignee | ||
Comment 2•21 years ago
|
||
The previous patch contained broken counting of unprefered methods:
--worseCounr;
That should be
++worseCount;
Attachment #156055 -
Attachment is obsolete: true
| Assignee | ||
Comment 3•21 years ago
|
||
I committed the fix.
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Summary: JVM-dependent resolution of ambiguity when calling Java methods → JVM-dependent resolution of ambiguity when calling Java methods
Target Milestone: --- → 1.5R6
Comment 4•21 years ago
|
||
Many thanx for investigating/fixing this issue, Igor!!! :-)
Will try it with next Rhino release ...
Merten
| Assignee | ||
Comment 5•21 years ago
|
||
Marking as verified since Merten Schumann confirmed that fix resolved original
problem.
Status: RESOLVED → VERIFIED
You need to log in
before you can comment on or make changes to this bug.
Description
•