I think pgilli1 wrote: [Charset iso-8859-1 unsupported, filtering to ASCII...] > I'm running into a strange problem when inserting a DefaultMutableTreeNode > object into my engine. I define the shadow fact, create a new instance and try > to create a fact and it fails.
It actually *doesn't* fail to assert the fact. It creates the fact, but fails to populate most of the slots, because that one getter method throws an exception. Those "SerializablePD" objects you see in the slots are the placeholder that exist in a shadow fact before the slot data has been inserted. When the exception is thrown, Jess aborts trying to populate the slots, but it goes ahead and puts the fact on the fact list (rather than possibly lose data; more on this below). When you call definstance a second time, you get a <Fact--1> return value -- that's a minus 1, meaning the object has already been definstanced. The fact you see on the fact list is the one from the first attempt. Most Beans don't throw exceptions from their getter methods, but some of the DefaultMutableTreeNode class's getter can indeed throw. Jess propagates the exception back to you, but preserves the fact on the fact list. Although this might not seem to make sense, it actually is just being careful -- what if the exception were happening not during the definstance, but during a later property change? You wouldn't want the fact to be removed from the fact list, right? If you're using definstance with a class whose getter methods can throw an exception, then you might want to do something like: (try (definstance simple ?dmtn static) catch (undefinstance ?dmtn)) On the other hand, you might want Jess to go ahead and keep the object on the fact list, and continue trying to populate the other slots via getters that don't throw exceptions. I'm definitely not opposed to an enhancement along these lines -- it would only be useful in a miniority of cases however, and I would need some input on the details of what the proper behavior should be. In that case, what should Jess do with the exception when getSomeSlot() throws? What if multiple getters throw? Is your proposal useful in the general case? But if I run definstance again, the fact is > inserted successfully! What the heck is going on to exhibit this behavior? > > See run below: > > > Jess> (defclass simple javax.swing.tree.DefaultMutableTreeNode) > javax.swing.tree.DefaultMutableTreeNode > > Jess> (bind ?dmtn (new javax.swing.tree.DefaultMutableTreeNode "Parent")) > <External-Address:javax.swing.tree.DefaultMutableTreeNode> > > Jess> (definstance simple ?dmtn static) > > Jess reported an error in routine DefinstanceList.createFact > while executing (definstance simple ?dmtn static). > Message: Called method threw an exception. > Program text: ( definstance simple ?dmtn static ) at line 4. > Nested exception is: > node has no children > > java.util.NoSuchElementException: node has no children > > at > javax.swing.tree.DefaultMutableTreeNode.getFirstChild(DefaultMutableTreeNode.j > ava:864) > > (note: rest of stack trace has been removed) > > Jess> (definstance simple ?dmtn static) > <Fact--1> > > Jess> (facts) > f-0 (MAIN::simple (allowsChildren TRUE) (childCount 0) (class > <External-Address:java.lang.Class>) (depth 0) (firstChild > <External-Address:jess.SerializablePD>) (firstLeaf > <External-Address:jess.SerializablePD>) (lastChild > <External-Address:jess.SerializablePD>) (lastLeaf > <External-Address:jess.SerializablePD>) (leaf > <External-Address:jess.SerializablePD>) (leafCount > <External-Address:jess.SerializablePD>) (level > <External-Address:jess.SerializablePD>) (nextLeaf > <External-Address:jess.SerializablePD>) (nextNode > <External-Address:jess.SerializablePD>) (nextSibling > <External-Address:jess.SerializablePD>) (parent > <External-Address:jess.SerializablePD>) (path > <External-Address:jess.SerializablePD>) (previousLeaf > <External-Address:jess.SerializablePD>) (previousNode > <External-Address:jess.SerializablePD>) (previousSibling > <External-Address:jess.SerializablePD>) (root > <External-Address:jess.SerializablePD>) (siblingCount > <External-Address:jess.SerializablePD>) (userObject > <External-Address:jess.SerializablePD>) (userObjectPath > <External-Address:jess.SerializablePD>) (OBJECT > <External-Address:javax.swing.tree.DefaultMutableTreeNode>)) > > For a total of 1 facts. > > > <End>Thats the end of the run</END> > > -------------------------------------------------------------------- > To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' > in the BODY of a message to [EMAIL PROTECTED], NOT to the list > (use your own address!) List problems? Notify [EMAIL PROTECTED] > -------------------------------------------------------------------- > --------------------------------------------------------- Ernest Friedman-Hill Distributed Systems Research Phone: (925) 294-2154 Sandia National Labs FAX: (925) 294-2234 Org. 8920, MS 9012 [EMAIL PROTECTED] PO Box 969 http://herzberg.ca.sandia.gov Livermore, CA 94550 -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED] --------------------------------------------------------------------