Issue1265
Created on 2009-02-22.04:37:53 by aviflax, last changed 2009-03-30.20:43:54 by aviflax.
File name |
Uploaded |
Description |
Edit |
Remove |
reflection_test.zip
|
aviflax,
2009-02-24.17:25:02
|
java class and jython script which illustrate the problem |
|
|
msg4155 (view) |
Author: Avi Flax (aviflax) |
Date: 2009-02-22.04:37:52 |
|
I'm working on using the Java library Restlet with Jython (going well,
plan to write an article about it soon) and I'm encountering this problem:
------------------------------------------------------------------
from org.restlet.resource import Resource
class my_resource(Resource):
def __init__(self):
Resource.__init__(self)
# By default, modifiable is False. Let's set it to True.
self.setModifiable(True)
# Prints True as one would expect
print my_resource().isModifiable()
# Create an instance using Java reflection
obj = my_resource.getClass(my_resource).getConstructor(my_resource,
None).newInstance(None)
# Prints False, which means that when one uses Java reflection, the
Jython subclass' constructor isn't properly called, or something
print obj.isModifiable()
------------------------------------------------------------------
result:
------------------------------------------------------------------
True
False
------------------------------------------------------------------
This is a showstopper for me, because Restlet internally uses reflection
all over the place.
Other than this issue, the project is going well. I look forward to
verification that my observation about this behaviour is correct!
|
msg4160 (view) |
Author: Avi Flax (aviflax) |
Date: 2009-02-24.14:31:51 |
|
One more thought: the constructor *is* being run, because if I set a
Python attribute on self, such as self.foo = bar, then _that_ *is*
accessible from the method. It's only modifying fields of the Java class
(via a setter) that seems to not function.
I wonder if this might have something to do with the constructor and the
method seeming to have references to different object instances? What I
mean is, if I add 'print str(self)' to the constructor and the method,
they print the Java object ID -- which is different!
|
msg4161 (view) |
Author: Frank Wierzbicki (fwierzbicki) |
Date: 2009-02-24.16:52:14 |
|
Are you able to reduce this to a simple Java class that shows the bug?
That would help us narrow down the cause.
|
msg4162 (view) |
Author: Avi Flax (aviflax) |
Date: 2009-02-24.17:04:33 |
|
Sure, I can do that!
|
msg4163 (view) |
Author: Avi Flax (aviflax) |
Date: 2009-02-24.17:25:02 |
|
attaching zipfile containing a java class and a jython script which
illustrate the problem
|
msg4164 (view) |
Author: Frank Wierzbicki (fwierzbicki) |
Date: 2009-02-25.19:09:00 |
|
Thanks for the test files, that should help.
|
msg4393 (view) |
Author: Frank Wierzbicki (fwierzbicki) |
Date: 2009-03-30.18:08:04 |
|
So I don't think this can really be fixed. Semantically I think you are
going around Jython by calling getClass() followed by getConstructor().
I don't see how we could intercept this sort of behavior in a general
way. Two workarounds:
you could call __init__ manually after calling the constructor, or you
can just call my_reticulator()
|
msg4396 (view) |
Author: Avi Flax (aviflax) |
Date: 2009-03-30.20:43:54 |
|
OK, I understand. I can work around it in my specific case fairly easily.
|
|
Date |
User |
Action |
Args |
2009-03-30 20:43:54 | aviflax | set | messages:
+ msg4396 |
2009-03-30 18:08:05 | fwierzbicki | set | status: open -> closed resolution: wont fix messages:
+ msg4393 |
2009-03-14 15:11:01 | fwierzbicki | set | priority: high |
2009-03-02 20:37:23 | fwierzbicki | set | assignee: fwierzbicki |
2009-02-25 19:09:00 | fwierzbicki | set | messages:
+ msg4164 |
2009-02-24 17:25:02 | aviflax | set | files:
+ reflection_test.zip messages:
+ msg4163 |
2009-02-24 17:04:33 | aviflax | set | messages:
+ msg4162 |
2009-02-24 16:52:14 | fwierzbicki | set | messages:
+ msg4161 |
2009-02-24 16:51:28 | fwierzbicki | set | nosy:
+ fwierzbicki |
2009-02-24 14:31:52 | aviflax | set | messages:
+ msg4160 |
2009-02-23 12:12:49 | cgroves | set | nosy:
+ cgroves |
2009-02-22 04:37:53 | aviflax | create | |
|