<html dir="ltr"><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style title="owaParaStyle"><!--P {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
--></style>
</head>
<body ocsi="x">
<div dir="ltr"><font color="#000000" size="2" face="Tahoma">SUMMARY:</font></div>
<div dir="ltr"><font size="2" face="tahoma">I am getting a NPE when using modify() with a JavaBean that implements PropertyChangeSupport.&nbsp;
</font></div>
<div dir="ltr"><font size="2" face="tahoma"></font>&nbsp;</div>
<div dir="ltr"><font size="2" face="tahoma">I have included the original source and a proposed fix.&nbsp; Stack trace is also included.</font></div>
<div dir="ltr"><font size="2" face="tahoma"></font>&nbsp;</div>
<div dir="ltr"><font size="2" face="tahoma">This applies to Drools 5.0.1, and has been verified to also be a problem for 5.1.0.M1.</font></div>
<div dir="ltr"><font size="2" face="tahoma"></font>&nbsp;</div>
<div dir="ltr"><font size="2" face="tahoma"></font>&nbsp;</div>
<div dir="ltr"><font size="2" face="tahoma">DETAIL:</font></div>
<div dir="ltr"><font color="#000000" size="2" face="Tahoma"></font>&nbsp;</div>
<div dir="ltr"><font color="#000000" size="2" face="Tahoma">I have a rule that looks like this:</font></div>
<div dir="ltr"><font size="2" face="tahoma"></font>&nbsp;</div>
<div dir="ltr"><b><font color="#960000" size="2"><font color="#960000" size="2">
<p align="left">rule</b></font></font><font size="2"> </font><font color="#008000" size="2"><font color="#008000" size="2">&quot;Constrain to owner or published to public&quot;</p>
</font></font><font size="2">
<p align="left"></font><b><font color="#960000" size="2"><font color="#960000" size="2">when</p>
</b></font></font><font size="2">
<p align="left">&nbsp; $fact : ListFact(</p>
<p align="left">&nbsp; path </font><b><font color="#960000" size="2"><font color="#960000" size="2">not</b></font></font><font size="2">
</font><b><font color="#960000" size="2"><font color="#960000" size="2">matches</b></font></font><font size="2">
</font><font color="#008000" size="2"><font color="#008000" size="2">&quot;.*owner.*&quot;</font></font><font size="2">,</p>
<p align="left">&nbsp; noopResponse == </font><b><font color="#960000" size="2"><font color="#960000" size="2">true</p>
</b></font></font><font size="2">
<p align="left">)</p>
<p align="left"></font><b><font color="#960000" size="2"><font color="#960000" size="2">then</b></font></font><font size="2">
</font></p>
<p align="left"></p>
<p align="left"><font color="#808000" size="2"><font color="#808000" size="2"></p>
</font></font><font size="2"></font><b><font color="#960000" size="2"><font color="#960000" size="2">&nbsp; modify</b></font></font><font size="2">($fact)
<p></p>
<p align="left">&nbsp; {</p>
<p align="left">&nbsp;&nbsp;&nbsp; setPath( </font><font color="#008000" size="2"><font color="#008000" size="2">&quot;[owner/username='' or publishlist/publish='All Users']&quot;</font></font><font size="2">)</p>
<p align="left">&nbsp; }</p>
<p align="left"></p>
<p align="left"></p>
</font><b><font color="#960000" size="2"><font color="#960000" size="2">
<p align="left">end</p>
</b></font></font></div>
<div dir="ltr"><font size="2" face="tahoma"></font>&nbsp;</div>
<div dir="ltr"><font size="2" face="tahoma">The $fact is a JavaBean that implements PropertyChangeSupport, and I've verified that everything is working correctly at the bean level.&nbsp; When I run this rule, I get this exception:</font></div>
<div dir="ltr"><font size="2" face="tahoma"></font>&nbsp;</div>
<div dir="ltr"><font size="1" face="Courier New">Caused by: java.lang.NullPointerException:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.drools.common.EqualityKey.removeFactHandle(EqualityKey.java:109)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:1435)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:1350)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.drools.common.AbstractWorkingMemory.propertyChange(AbstractWorkingMemory.java:1577)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:339)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:276)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at com.infotrustgroup.rules.RestFact.setPath(RestFact.java:264)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at com.infotrustgroup.facts.ParametersFact.setPath(ParametersFact.java:105)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at com.infotrustgroup.facts.ParametersFact.setPath(ParametersFact.java:74)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at com.infotrustgroup.what.Rule_Constrain_to_owner_or_published_to_public_0.consequence(Rule_Constrain_to_owner_or_published_to_public_0.java:12)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at com.infotrustgroup.what.Rule_Constrain_to_owner_or_published_to_public_0ConsequenceInvoker.evaluate(Rule_Constrain_to_owner_or_published_to_public_0ConsequenceInvoker.java:23)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:934)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ... 38 more</font></div>
<div dir="ltr"><font size="1" face="Courier New"></font>&nbsp;</div>
<div dir="ltr"><font size="2" face="Tahoma">The offending line is marked below.&nbsp; It looks like maybe &quot;this.instances&quot; is null in the &quot;else&quot; clause.</font></div>
<div dir="ltr"><font size="2" face="Tahoma"></font>&nbsp;</div>
<div dir="ltr"><font size="1" face="courier new">&nbsp;&nbsp;&nbsp; public void removeFactHandle(final InternalFactHandle handle) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( this.handle == handle ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( this.instances == null ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.handle = null;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.handle = (InternalFactHandle) this.instances.remove( 0 );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( this.instances.isEmpty() ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.instances = null;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ***<strong><em>this.instances.remove( handle );***<br>
</em></strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( this.instances.isEmpty() ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.instances = null;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }</font></div>
<div dir="ltr"><font size="1" face="courier new"></font>&nbsp;</div>
<div dir="ltr"><font size="2" face="Tahoma">It looks like someone else ran into this problem before, but only fixed it for the &quot;if&quot; portion, not the &quot;else&quot; portion.&nbsp; I modified the code as follows, and this seems to fix the NPE.&nbsp; Basically, I followed the pattern
 from the &quot;if&quot; portion.</font></div>
<div dir="ltr"><font size="2" face="Tahoma"></font>&nbsp;</div>
<div dir="ltr"><font size="1" face="Courier New">&nbsp;&nbsp;&nbsp; public void removeFactHandle(final InternalFactHandle handle) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( this.handle == handle ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( this.instances == null ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.handle = null;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.handle = (InternalFactHandle) this.instances.remove( 0 );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( this.instances.isEmpty() ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.instances = null;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<br>
&nbsp;&nbsp;&nbsp;if(this.instances == null)<br>
&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;this.handle = null;<br>
&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;else<br>
&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;this.instances.remove( handle );<br>
&nbsp;&nbsp;&nbsp;&nbsp;if ( this.instances.isEmpty() ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.instances = null;<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<br>
</font></div>
<div dir="ltr"><font size="2" face="Tahoma">Please read around the formatting.&nbsp; Can someone verify if this is a correct fix, and if it should be applied to the codebase?&nbsp; It seems to work for me.&nbsp; It does not break any unit tests in drools-core 5.0.1 either.</font></div>
<div dir="ltr"><font size="2" face="Tahoma"></font>&nbsp;</div>
<div><font size="2" face="Tahoma">
<p style="MARGIN: 0in 0in 0pt" class="MsoNormal"><b><span style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 10pt">Jason Smith<br>
Software Engineer </span></b><b><span style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 8pt"><br>
</span></b><b><span style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 10pt">InfoTrust Group, Inc.</span></b></p>
<p style="MARGIN: 0in 0in 0pt" class="MsoNormal"><b><span style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 10pt"></span></b><span style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 8pt">500 Discovery Parkway, Suite 200</span><br>
<span style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 8pt">Superior, CO 80027</span><br>
<b><span style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 8pt">Office</span></b><span style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 8pt"> 303-627-6571<br>
<b>Fax</b> 303-666-6711</span><span style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: navy; FONT-SIZE: 8pt"><br>
</span><b><span style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 8pt">Email</span></b><span style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: navy; FONT-SIZE: 8pt">
<u><font color="#0000ff"><a href="mailto:jsmith@infotrustgroup.com">jsmith@infotrustgroup.com</a></font></u></span></p>
<p style="MARGIN: 0in 0in 0pt" class="MsoNormal"><b><span style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 8pt">WEB</span></b><span style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: navy; FONT-SIZE: 8pt">
</span><span style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: blue; FONT-SIZE: 8pt"><a href="http://www.infotrustgroup.com/">www.infotrustgroup.com</a></span></p>
<span style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: blue; FONT-SIZE: 8pt">
<p class="MsoNormal"><i><span style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 8pt">This e-mail and all information included herein do not constitute a legal agreement accorded by INFOTRUST GROUP and its affiliates and subsidiaries.&nbsp; All legal
 agreements must be formulated in writing by a legal representative of INFOTRUST GROUP.&nbsp;This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed.&nbsp; If you have received
 this e-mail by mistake, please inform us and destroy this e-mail and any documents it might contain.&nbsp; Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Finally,
 the recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.&nbsp; Thank you for your cooperation.</span></i></p>
</span></font></div>
</body>
</html>