Mantis - Quercus
Viewing Issue Advanced Details
3748 feature always 11-05-09 12:52 11-07-09 17:45
PeterJ  
nam  
normal  
closed 4.0.2  
fixed  
none    
none 4.0.2  
0003748: Avoid recursive instropection of methods.
At the end of ...program.JavaClassDef.introspectMethods, the method calls itself recursively, first for the superclasses and then for the interfaces. This does not appear to be necessary because the line type.getMethods() already provided all of the methods from the superclasses and the interfaces. Even the code in AbstractJavaMethod.overload seems to acknowledge that the superclass and interface methods can be previously processed.

Removing this recursion would provide some performance benefit because the amount of duplicate effort would be eliminated, and the extra garbage generated by overriding the entries in _functionMap would be avoided.

In addition, it would benefit developers who are attempting to extend the existing capabilities. For example, I am attempting to provide support for another database, but I do not want to support as PHP functions some of the methods that are provided in JdbcConnectionResource. Unfortunately, overriding the method in my class and adding a @Hide annotation does not work because of the recursion in introspectMethods - the overridden methods get added as functions for my PHP class anyway.

Finally, I also noticed that the public methods on java.lang.Object are added as functions available to the PHP class. I don't think that this was intended so the attached patch includes a test to eliminate those methods.

By the way, if my logic is flawed and there is a perfectly valid reason for the recursion, then it would be nice if a comment explaining WHY THE RECURSION IS NECESSARY would appear in the code. I hate attempting to make sense of someone else's code when they have not commented on WHY they wrote the code the way they did, especially if the code in question does not make obvious sense (in the way that this recursion makes no obvious sense).
 quercus_introspect_recursion.txt [^] (953 bytes) 11-05-09 12:52

Notes
(0004289)
nam   
11-05-09 19:23   
You are right that we don't want to add java.lang.Object methods to PHP classes. However, we do want to add those methods to Java classes. So we'll need to distinguish between the two and put in the fix accordingly.
(0004290)
nam   
11-07-09 17:34   
php/0cja

Method introspection is fixed for 4.0.2, so @Hide should work as expected.
(0004291)
nam   
11-07-09 17:45   
php/4a40

java.lang.Object methods are not added to Java-backed PHP classes anymore