Skip to content

Commit 96757ae

Browse files
committed
made method matching handle differ only in return type, resolving to more-derived return type when bridge methods are involved
tweaked RT.load for Android tweaked DynamicClassLoader parenting for Android Android now works if you comment out bean in core_proxy.clj (java.beans is not supported on Android)
1 parent 43e0f98 commit 96757ae

File tree

3 files changed

+37
-32
lines changed

3 files changed

+37
-32
lines changed

src/jvm/clojure/lang/Compiler.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,9 +1101,14 @@ public InstanceMethodExpr(String source, int line, Expr target, String methodNam
11011101
if(methods.size() > 1)
11021102
{
11031103
ArrayList<Class[]> params = new ArrayList();
1104+
ArrayList<Class> rets = new ArrayList();
11041105
for(int i = 0; i < methods.size(); i++)
1105-
params.add(((java.lang.reflect.Method) methods.get(i)).getParameterTypes());
1106-
methodidx = getMatchingParams(methodName, params, args);
1106+
{
1107+
java.lang.reflect.Method m = (java.lang.reflect.Method)methods.get(i);
1108+
params.add(m.getParameterTypes());
1109+
rets.add(m.getReturnType());
1110+
}
1111+
methodidx = getMatchingParams(methodName, params, args,rets);
11071112
}
11081113
java.lang.reflect.Method m =
11091114
(java.lang.reflect.Method) (methodidx >= 0 ? methods.get(methodidx) : null);
@@ -1249,9 +1254,14 @@ public StaticMethodExpr(String source, int line, Class c, String methodName, IPe
12491254
if(methods.size() > 1)
12501255
{
12511256
ArrayList<Class[]> params = new ArrayList();
1257+
ArrayList<Class> rets = new ArrayList();
12521258
for(int i = 0; i < methods.size(); i++)
1253-
params.add(((java.lang.reflect.Method) methods.get(i)).getParameterTypes());
1254-
methodidx = getMatchingParams(methodName, params, args);
1259+
{
1260+
java.lang.reflect.Method m = (java.lang.reflect.Method) methods.get(i);
1261+
params.add(m.getParameterTypes());
1262+
rets.add(m.getReturnType());
1263+
}
1264+
methodidx = getMatchingParams(methodName, params, args,rets);
12551265
}
12561266
method = (java.lang.reflect.Method) (methodidx >= 0 ? methods.get(methodidx) : null);
12571267
if(method == null && RT.booleanCast(RT.WARN_ON_REFLECTION.get()))
@@ -2007,7 +2017,7 @@ static boolean subsumes(Class[] c1, Class[] c2){
20072017
return better;
20082018
}
20092019

2010-
static int getMatchingParams(String methodName, ArrayList<Class[]> paramlists, IPersistentVector argexprs)
2020+
static int getMatchingParams(String methodName, ArrayList<Class[]> paramlists, IPersistentVector argexprs, List<Class> rets)
20112021
throws Exception{
20122022
//presumes matching lengths
20132023
int matchIdx = -1;
@@ -2033,8 +2043,12 @@ static int getMatchingParams(String methodName, ArrayList<Class[]> paramlists, I
20332043
matchIdx = i;
20342044
tied = false;
20352045
}
2036-
else if(!(subsumes(paramlists.get(matchIdx), paramlists.get(i))
2037-
|| Arrays.equals(paramlists.get(matchIdx), paramlists.get(i))))
2046+
else if(Arrays.equals(paramlists.get(matchIdx), paramlists.get(i)))
2047+
{
2048+
if(rets.get(matchIdx).isAssignableFrom(rets.get(i)))
2049+
matchIdx = i;
2050+
}
2051+
else if(!(subsumes(paramlists.get(matchIdx), paramlists.get(i))))
20382052
tied = true;
20392053
}
20402054
}
@@ -2060,13 +2074,15 @@ public NewExpr(Class c, IPersistentVector args, int line) throws Exception{
20602074
Constructor[] allctors = c.getConstructors();
20612075
ArrayList ctors = new ArrayList();
20622076
ArrayList<Class[]> params = new ArrayList();
2077+
ArrayList<Class> rets = new ArrayList();
20632078
for(int i = 0; i < allctors.length; i++)
20642079
{
20652080
Constructor ctor = allctors[i];
20662081
if(ctor.getParameterTypes().length == args.count())
20672082
{
20682083
ctors.add(ctor);
20692084
params.add(ctor.getParameterTypes());
2085+
rets.add(c);
20702086
}
20712087
}
20722088
if(ctors.isEmpty())
@@ -2075,7 +2091,7 @@ public NewExpr(Class c, IPersistentVector args, int line) throws Exception{
20752091
int ctoridx = 0;
20762092
if(ctors.size() > 1)
20772093
{
2078-
ctoridx = getMatchingParams(c.getName(), params, args);
2094+
ctoridx = getMatchingParams(c.getName(), params, args, rets);
20792095
}
20802096

20812097
this.ctor = ctoridx >= 0 ? (Constructor) ctors.get(ctoridx) : null;

src/jvm/clojure/lang/DynamicClassLoader.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ public class DynamicClassLoader extends URLClassLoader{
2727
static final URL[] EMPTY_URLS = new URL[]{};
2828

2929
public DynamicClassLoader(){
30-
super(EMPTY_URLS,Thread.currentThread().getContextClassLoader());
31-
//super(Compiler.class.getClassLoader());
30+
//pseudo test in lieu of hasContextClassLoader()
31+
super(EMPTY_URLS,(Thread.currentThread().getContextClassLoader() == null ||
32+
Thread.currentThread().getContextClassLoader() == ClassLoader.getSystemClassLoader())?
33+
Compiler.class.getClassLoader():Thread.currentThread().getContextClassLoader());
34+
// super(EMPTY_URLS,Compiler.class.getClassLoader());
3235
}
3336

3437
public DynamicClassLoader(ClassLoader parent){

src/jvm/clojure/lang/RT.java

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -381,47 +381,33 @@ static public void load(String scriptbase, boolean failIfNotFound) throws Except
381381
String cljfile = scriptbase + ".clj";
382382
URL classURL = baseLoader().getResource(classfile);
383383
URL cljURL = baseLoader().getResource(cljfile);
384-
boolean failed = false;
384+
boolean loaded = false;
385385

386-
if(classURL != null &&
387-
(cljURL == null
388-
|| lastModified(classURL, classfile) > lastModified(cljURL, cljfile)))
386+
if((classURL != null &&
387+
(cljURL == null
388+
|| lastModified(classURL, classfile) > lastModified(cljURL, cljfile)))
389+
|| classURL == null)
389390
{
390391
try
391392
{
392393
Var.pushThreadBindings(
393394
RT.map(CURRENT_NS, CURRENT_NS.get(),
394395
WARN_ON_REFLECTION, WARN_ON_REFLECTION.get()));
395-
loadClassForName(scriptbase.replace('/','.') + LOADER_SUFFIX);
396+
loaded = (loadClassForName(scriptbase.replace('/','.') + LOADER_SUFFIX) != null);
396397
}
397398
finally
398399
{
399400
Var.popThreadBindings();
400401
}
401402
}
402-
else if(cljURL != null)
403+
if(!loaded && cljURL != null)
403404
{
404405
if (booleanCast(Compiler.COMPILE_FILES.get()))
405406
compile(cljfile);
406407
else
407408
loadResourceScript(RT.class, cljfile);
408409
}
409-
else
410-
{
411-
try
412-
{
413-
Var.pushThreadBindings(
414-
RT.map(CURRENT_NS, CURRENT_NS.get(),
415-
WARN_ON_REFLECTION, WARN_ON_REFLECTION.get()));
416-
failed = loadClassForName(scriptbase.replace('/','.') + LOADER_SUFFIX) == null;
417-
}
418-
finally
419-
{
420-
Var.popThreadBindings();
421-
}
422-
}
423-
424-
if(failed && failIfNotFound)
410+
else if(!loaded && failIfNotFound)
425411
throw new FileNotFoundException(String.format("Could not locate %s or %s on classpath: ", classfile, cljfile));
426412
}
427413

0 commit comments

Comments
 (0)