From: jz c. <jz....@ho...> - 2013-03-31 21:48:47
|
Hi there, I may figure out the possible place for this exception root cause. it looks like mandarax FactImpl.java has some concurrency issue, esp the following code: 275: /** 276: * Get the positive literals. 277: * @return the collection of positive literals, this is a singleton containing only this object 278: */ 279: public java.util.List getPositiveLiterals() { 280: if (posLiterals == null) { 281: posLiterals = new java.util.Vector(1); 282: posLiterals.add(this ); 283: } 284: 285: return posLiterals; 286: } 287: 288: /**if two threads run the code as follows:Thread1: if null checkthread2: if null checkthread1: new vectorthread2: new vectorthread1: add fact (this)thread2: add fact (this) It will end up have two facts in vector (postiveLiteral), and hence it will lead to the position that negativelLiteral is empty, but positiveLiteral is not empty.I did the following change for this issue:add volatile to posLiterals declarationand then add synchonized block for this method as follows:public java.util.List getPositiveLiterals() { if(posLiterals == null) { synchronized (this) { if (posLiterals == null) { posLiterals = new java.util.Vector(1); posLiterals.add(this); } }} return posLiterals; }Please let me know you thoughts. Thanks.JZ From: jz....@ho... To: j.b...@ma...; man...@li...; man...@li... Subject: IndexOutOfBoundsException from ResolutionInferenceEngine4 Date: Tue, 5 Feb 2013 17:53:24 -0800 Hi there, I encounter IndexOutOfBoundsException when using mandarax ResolutionInferenceEngine4. The exception is thrown at the following position (line 177): 158: // if the goal is the empty clause, return success 159: if (goal.isEmpty()) { 160: if (logOn) { 161: LOG_IE_STEP.debug("Derivation successful !"); 162: } 163: results.add(node); 164: // new in 3.2: notify listener 165: notifyListenersOnResult(session, logOn); 166: 167: node.setResultNode(true); 168: node.setSupported(results.size() - 1); 169: node.setFailed(false); 170: // check whether we have enough results 171: if (cardinalityConstraint != ALL) { 172: node 173: .setLastNode((results.size() >= cardinalityConstraint)); 174: } 175: return node; 176: } 177: String goalPredicateName = ((Fact) goal.getNegativeLiterals() 178: .get(0)).getPredicate().getName();http://www.java2v.com/Open-Source/Java-Document/Rule-Engine/Mandarax/org/mandarax/reference/ResolutionInferenceEngine4.java.htm Have you encountered this issue? I did some source code reading and find out that goal is of type: TmpClause.java. Its isEmpty implementation is actually checking if both negativeLiterals and positiveLiterals are empty. therefore if negativeLiterals is empty, but the postiveLiterals is not empty, then goal.isEmpty will be false, and line 177 will throw IndexOutOfBoundsException. Do you know what actually does it mean by empty negative literals and nonempty positive literals of a goal? Thanks for your help in advance. JZ |