Skip to content

Commit 8ed6412

Browse files
hansonrhansonr
authored andcommitted
Java2Script 3.2.2 java.lang.reflect.Proxy fix
Note that functional interface methods (methods in singleton Interfaces) are still aliased both in their fully parameterized forms and their unparameterized forms. This works for proxy, but it is not ideal. Ideally, we would be giving the minimum signature for the interface method parameters. I just don't have a way of doing that.
1 parent 5c19423 commit 8ed6412

File tree

10 files changed

+168
-111
lines changed

10 files changed

+168
-111
lines changed
149 Bytes
Binary file not shown.
331 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20180730064459
1+
20180730180217
149 Bytes
Binary file not shown.
331 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20180730064459
1+
20180730180217

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/Java2ScriptVisitor.java

Lines changed: 148 additions & 93 deletions
Large diffs are not rendered by default.
149 Bytes
Binary file not shown.

sources/net.sf.j2s.java.core/src/java/lang/reflect/Method.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
*/
2626
public final class Method extends AccessibleObject implements GenericDeclaration, Member {
2727

28-
private Object signature;
28+
29+
private String signature;
2930
private Class<?> Class_;
3031
// This is guaranteed to be interned by the VM in the 1.4
3132
// reflection implementation
@@ -346,6 +347,12 @@ public Class<?> getReturnType() {
346347
return returnType;
347348
}
348349

350+
351+
@Override
352+
public String getSignature() {
353+
return (String) signature;
354+
}
355+
349356
/**
350357
* Answers an integer hash code for the receiver. Objects which are equal answer
351358
* the same value for this method. The hash code for a Method is the hash code

sources/net.sf.j2s.java.core/src/java/lang/reflect/Proxy.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -672,32 +672,27 @@ private static Class<?> defineClass0(ClassLoader loader, String name, Class<?>[]
672672
for (int i = 0; i < interfaces.length; i++) {
673673
Method[] methods = interfaces[i].getDeclaredMethods();
674674
for (int j = 0; j < methods.length; j++) {
675-
setJSPrototype(cl, methods[j]);
675+
setJSPrototype(cl, methods[j], false);
676676
}
677-
677+
if (methods.length == 1)
678+
setJSPrototype(cl, methods[0], true);
678679
}
679680
return cl;
680681
}
681682

682683
@SuppressWarnings("unused")
683-
private static void setJSPrototype(Class<?> cl, Method m) {
684+
private static void setJSPrototype(Class<?> cl, Method m, boolean isFunctionalInterfaceMethod) {
684685
String mname = m.getName();
686+
685687
// SwingJS transfers the invocation to a temporary method, then invokes it
686688
/**
687689
* @j2sNative
688690
*
689-
* m.Class_ = cl;
690-
* m.isProxy = true;
691-
* cl.$clazz$.prototype[mname] = function() {
692-
* var args = new Array(arguments.length);
693-
* for (var k = arguments.length; --k >= 0;)args[k] = arguments[k];
694-
* this.h.invoke$O$reflect_Method$OA(this, m, args);
695-
* }
691+
* if (isFunctionalInterfaceMethod) { mname = mname.split("$")[0] + "$"; }
692+
* m.Class_ = cl; m.isProxy = true; cl.$clazz$.prototype[mname] =
693+
* function() { var args = new Array(arguments.length); for (var k =
694+
* arguments.length; --k >= 0;)args[k] = arguments[k];
695+
* this.h.invoke$O$reflect_Method$OA(this, m, args); }
696696
*/
697-
{
698-
699-
}
700-
701-
702697
}
703698
}

0 commit comments

Comments
 (0)