Here's the test case. There are three files. First I'll tell you what's in them, then 
I'll
tell you what's perplexing about the case. Total for the three files  is 92 lines of 
code.

blah.tcl: the Tcl script that often gets a weird error like 'invalid command name
"java0x3"'.
Four.java: the Java class used by the Tcl script. Has the static variable.
MakeTclList.java: a Tcl extension written in Java, used by the Tcl script. Turns a Java
Vector into a Tcl list.

If I remove the use of MakeTclList, the bad symptom goes away, which makes me 
suspicious of
MakeTclList, so I would certainly appreciate your review of that class. But it is 
correct
as far as I understand things.

Now, here's the perplexing part. I get the "invalid command name" message about 50% of 
the
time only--and only when I run it under StoryServer! I have not been able to reproduce 
it
under the Tcl shell. The only funny thing I know that StoryServer does is evaluate
everything in a particular Tcl namespace, and delete and recreate that namespace prior 
to
each page generation. I have emulated that under the Tcl shell, and still cannot 
reproduce
the problem there.

I will continue to try to refine this test case, and reproduce it under the Tcl shell.

Thanks a lot for your help.

blah.tcl
-------------------------
 set compositor [java::new com.dna.tclblendbug.Four]
 set content [$compositor composite dna_basics]
 set dataList [makeTclList $content]
 foreach data $dataList {
        set str [$data elementAt 0]
        puts "string is [$str toString]<br>"
 }

Four.java
-------------------------
package com.dna.tclblendbug;

import java.util.Hashtable;
import java.util.Vector;

public class Four
{
        private static Hashtable cache = new Hashtable ();

        public Vector composite (String arg)
        {
                Vector cacheHit = (Vector) cache.get (arg);

                if (cacheHit != null)
                {
                        return cacheHit;
                }

                Vector v = new Vector ();

                Vector out = new Vector ();

                out.addElement ("poobah");

                v.addElement (out);

                cache.put (arg, v);

                return v;
        }
}

MakeTclList.java
-------------------------
package com.dna.platform.tcl;

import java.util.Vector;
import tcl.lang.Command;
//import tcl.lang.InternalRep;
import tcl.lang.Interp;
import tcl.lang.ReflectObject;
import tcl.lang.TclException;
import tcl.lang.TclList;
import tcl.lang.TclObject;
import tcl.lang.TclString;

class MakeTclList implements Command
{
        public void cmdProc (Interp interp, TclObject argv [])
        {
                interp.resetResult ();

                if (interp == null || argv == null || argv.length != 2)
                {
                        return;
                }

                TclObject arg = argv [1];

                if (arg == null)
                {
                        return;
                }

// maybe not needed
//              InternalRep argRep = arg.getInternalRep ();
//
//              if (! (argRep instanceof ReflectObject))
//              {
//                      return;
//              }
//

                Object obj;

                try
                {
                        obj = ReflectObject.get (interp, arg);
                }
                catch (TclException e)
                {
                        obj = null;
                }

                if (! (obj instanceof Vector))
                {
                        return;
                }

                Vector v = (Vector) obj;

                TclObject list = TclList.newInstance ();

                int i, n = v.size ();

                for (i = 0; i < n; ++ i)
                {
                        Object o = v.elementAt (i);

                        try
                        {
                                if (o instanceof String)
                                {
                                        TclList.append (interp, list, 
TclString.newInstance
((String) o));
                                }
                                else
                                {
                                        // We are not supposed to use getClass (); I 
have
never been sure why.
                                        // In this case, no subclasses are involved 
anyway,
so the result
                                        // should be the same.
                                        TclList.append (interp, list,
ReflectObject.newInstance (interp, o.getClass (), o));
                                }
                        }
                        catch (TclException e)
                        {
                        }
                }

                interp.setResult (list);
        }
}

Sample Error
-------------------------
Tcl Error During Template Execution

     invalid command name "java0x3"
         while executing
     "$data elementAt 0"
         ("foreach" body line 2)
         invoked from within
     "foreach data $dataList {
                     set str [$data elementAt 0]
                     puts "string is [$str toString]<br>"
             }
     "

Invoked From: template path /dna/test/Wes6

Error Occurred In Command Block At Lines 1-9:

             set compositor [java::new com.dna.tclblendbug.Four]
             set content [$compositor composite dna_basics]
             set dataList [makeTclList $content]
             foreach data $dataList {
                     set str [$data elementAt 0]
                     puts "string is [$str toString]<br>"
             }

Elapsed Execution Time: 0.008 seconds



Template Variables:

      variable                                       value
      ID
      TABLE
      ::VgnDefaultNamespace::ssuid             Maw1BM00caU0000yeldTLOW0i7
      ::VgnDefaultNamespace::data               java0x3
      ::VgnDefaultNamespace::dataList          java0x3
      ::VgnDefaultNamespace::content           java0x6
      ::VgnDefaultNamespace::compositor     java0x5
      ssuid                                                    
Maw1BM00caU0000yeldTLOW0i7


----------------------------------------------------------------
The TclJava mailing list is sponsored by Scriptics Corporation.
To subscribe:    send mail to [EMAIL PROTECTED]  
                 with the word SUBSCRIBE as the subject.
To unsubscribe:  send mail to [EMAIL PROTECTED] 
                 with the word UNSUBSCRIBE as the subject.
To send to the list, send email to '[EMAIL PROTECTED]'. 
An archive is available at http://www.mail-archive.com/tcljava@scriptics.com

Reply via email to