[kepler-dev] Possible bug: variable name must equal MoML name

Christopher Brooks cxh at eecs.berkeley.edu
Tue Oct 12 10:21:40 PDT 2004


Actually, the bug is in Entity.clone().  The code looks for ports
by name.  If one is not found, then the port in the clone is not
properly initialized.  I modified Entity.clone() so that it detects
this situation and throws a somewhat more informative error message.
I wrote a simple test class called PortNameProblem.java, checked it
in to ptolemy/kernel/test and added a test to Entity.tcl.
I removed the interim test I had added in domains/pn/test.

The change to Entity.tcl looks like:

***************
*** 181,192 ****
              for (int i = 0; i < fields.length; i++) {
                  try {
                      if (fields[i].get(newEntity) instanceof Port) {
!                         fields[i].set(newEntity,
!                                 newEntity.getPort(fields[i].getName()));
                      }
!                 } catch (IllegalAccessException e) {
!                     throw new CloneNotSupportedException(e.getMessage() +
!                             ": " + fields[i].getName());
                  }
              }
              _cloneFixAttributeFields(newEntity);
--- 181,214 ----
              for (int i = 0; i < fields.length; i++) {
                  try {
                      if (fields[i].get(newEntity) instanceof Port) {
!                         Port port = newEntity.getPort(fields[i].getName());
!                         if (port == null) { 
!                             throw new IllegalActionException(this,
!                                     "Could not find a port named '"
!                                     + fields[i].getName() + "'. "
!                                     + "This can occur when the name of the "
!                                     + "variable does not match the name "
!                                     + "passed to the constructor of the "
!                                     + "actor.\n"
!                                     + "Right:\n"
!                                     + "    input = new TypedIOPort(this, "
!                                     + "\"input\", true, false);\n"
!                                     + "Wrong:\n"
!                                     + "    myInput = new TypedIOPort(this, "
!                                     + "\"input\", true, false);");
!                         } else {
!                             fields[i].set(newEntity, port);
!                         }
                      }
!                 } catch (Exception ex) {
!                     // CloneNotSupportedException does not have a
!                     // constructor that takes a cause argument, so we call
!                     // initCause() and then throw.
!                     CloneNotSupportedException cloneException =
!                         new CloneNotSupportedException("Problem cloning '"
!                                 + fields[i].getName() + "'");
!                     cloneException.initCause(ex);
!                     throw cloneException;
                  }
              }
              _cloneFixAttributeFields(newEntity);


When the exception occurs, the message looks like:

ptolemy.kernel.util.IllegalActionException: Could not find a port named 'badlyNamedInput'. This can occur when the name of the variable does not match the name passed to the constructor of the actor.
Right:
    input = new TypedIOPort(this, "input", true, false);
Wrong:
    myInput = new TypedIOPort(this, "input", true, false);
  in .E1

_Christopher
--------

    Looks like a bug in the Ptolemy II class mechanism.
    
    I've checked in your example as a test in
    domains/pn/test/NameProblem.xml and
    domains/pn/test/auto/NameProblemTest.xml
    
    I poked around for a solution be have not found one.  I'll see what I
    can do.  
    
    I also fixed a bug in actor/process/ProcessThread.java where
    the NullPointerException message was going to stderr instead of being
    displayed in a stack trace window.
    
    _Christopher
    
    --------
        Hi,
        
        In the process of writing an actor, Ilkay and I encountered a possible=
   20=
        
        bug in the implementation of the code that allows instantiation of a=20
        class in the workflow.
        
        Attached are the workflow and the actor that demonstrates this problem.
        
        In the attached actor code, there's a port that's instantiated as:
        
        inputo =3D new TypedIOPort(this, "input", true, false);
        
        
        So the variable name is "inputo", but it is named "input" in the MoML.
        
        When I run this workflow, I get:
        
        
        
        Exception in thread ".np.InstanceOfClass2.NameProblem"=20
        java.lang.RuntimeException: java.lang.NullPointerException
        =A0=A0=A0=A0=A0=A0=A0 at=20
        ptolemy.actor.process.ProcessThread.run(ProcessThread.java:219)
        Caused by: java.lang.NullPointerException
        =A0=A0=A0=A0=A0=A0=A0 at NameProblem.fire(NameProblem.java:28)
        =A0=A0=A0=A0=A0=A0=A0 at=20
        ptolemy.actor.process.ProcessThread.run(ProcessThread.java:181)
        Exception in thread ".np.InstanceOfClass.NameProblem"=20
        java.lang.RuntimeException: java.lang.NullPointerException
        =A0=A0=A0=A0=A0=A0=A0 at=20
        ptolemy.actor.process.ProcessThread.run(ProcessThread.java:219)
        Caused by: java.lang.NullPointerException
        =A0=A0=A0=A0=A0=A0=A0 at NameProblem.fire(NameProblem.java:28)
        =A0=A0=A0=A0=A0=A0=A0 at=20
        ptolemy.actor.process.ProcessThread.run(ProcessThread.java:181)
        
        
        However, interestingly enough, if I rename the variable to "input", and
   =20=
        
        thus match the MoML name, there's no exception.
        
        So somehow, the workflow only runs if the variable name is the same as=
   20=
        
        the MoML name.
        
        Is this a bug in Ptolemy or is something missing in my understanding of
   =20=
        
        writing actors?
        
        
        Thanks in advance for the help!
        Xiaowen
        
        
        
        
    <<attachments deleted>>
    
    ---------------------------------------------------------------------------
   -
    Posted to the ptolemy-hackers mailing list.  Please send administrative
    mail for this list to: ptolemy-hackers-request at ptolemy.eecs.berkeley.edu
--------



More information about the Kepler-dev mailing list