Re: [tcljava-dev] Testcase for bug 2072924
Brought to you by:
mdejong
|
From: Mo D. <mo...@mo...> - 2009-02-03 07:19:55
|
Tom Poindexter wrote:
> I've been looking into the bug I filed a while back, and developed
> a stand alone test case that illustrates the behavior.
>
> Itcl class Foo resembles my actual environment. It wraps up
> a Java object, and the destructor does an explicit 'rename' to
> get rid of the object command.
>
>
Tom
The short answer is that you have in fact found a bug. The longer answer
is I need to look at it some more to really be sure the fix is right.
Here is a trimmed down test case that reproduces the problem without
Itcl or anything else involved.
package require java
# Create table, add StringBuffer to the table
set table [java::new java.util.HashMap]
set key_obj [java::new String fookey]
set value_obj [java::new java.lang.StringBuffer fooval]
$table put $key_obj $value_obj
# Lookup the Java object in the table, this will return
# a new ref since the return type of the method is
# Object but the original reflected type was StringBuffer.
set lookup_ref [$table get $key_obj]
set cmd "rename $lookup_ref {}"
# Evaluate this command to delete the Tcl command for
# the Java object currently reflected in lookup_ref.
eval $cmd
# Now query the Java object in the table, this must
# not return the now stale ref currently contained
# in value_obj.
set new_ref [$table get $key_obj]
# This command will fail if an invalid ref was returned
$new_ref toString
BROKEN OUTPUT:
$ jaclsh
% package require java
% set table [java::new java.util.HashMap]
java0x1
% set key_obj [java::new String fookey]
java0x2
% set value_obj [java::new java.lang.StringBuffer fooval]
java0x3
% $table put $key_obj $value_obj
java0x0
% set lookup_ref [$table get $key_obj]
java0x4
% set cmd "rename $lookup_ref {}"
rename java0x4 {}
% eval $cmd
% set new_ref [$table get $key_obj]
java0x4
% $new_ref toString
invalid command name "java0x4"
NOT BROKEN:
% set new_ref [$table get $key_obj]
java0x5
% $new_ref toString
fooval
Now, you can get these fixed results by making the change described in
this patch, but this is just a work in progress. It is for hacking
purposes only!
diff -u -r orig/jacl1.4.1/src/tcljava/tcl/lang/ReflectObject.java
jacl1.4.1/src/tcljava/tcl/lang/ReflectObject.java
--- orig/jacl1.4.1/src/tcljava/tcl/lang/ReflectObject.java Thu Apr
13 00:36:50 2006
+++ jacl1.4.1/src/tcljava/tcl/lang/ReflectObject.java Mon Feb 2
22:38:48 2009
@@ -512,7 +512,7 @@
ReflectObject roRep = findInReflectTable(interp, cl, obj);
- if (roRep != null) {
+ if (roRep != null && roRep.isValid) {
// If it is already in the table just increment the use count
and return
it
roRep.useCount++;
I am not 100% sure about this patch, because it seems that the
duplicated entries and not being cleared out of the reflect table like
they should be. More on that to come.
cheers
Mo DeJong
|