<br>&nbsp;&nbsp; Marcus, can you please open a JIRA for us, anyway, so that we can improve that code spot to check for nulls? This will avoid such problems in the future.<br><br>&nbsp;&nbsp; If you want to contribute a patch, it is also welcome.<br>
<br>&nbsp;&nbsp; Thanks.<br>&nbsp;&nbsp; Edson<br><br><div class="gmail_quote">2008/5/19 Marcus Ilgner &lt;<a href="mailto:marcus.ilgner@gmail.com">marcus.ilgner@gmail.com</a>&gt;:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Edson,<br>
<br>
thank you very much for testing this! Since I could not discern any<br>
differences between your approach and mine, I decided to resolve the<br>
issue manually by inserting a work-around in my test routine which<br>
sets the context class loader for the current thread before calling<br>
the method under test.<br>
<br>
if (Thread.currentThread().getContextClassLoader() == null) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp;Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());<br>
}<br>
<br>
My guess is that the custom JUnit 4 class runner<br>
(SpringJUnit4ClassRunner) somehow is responsible for the faulty<br>
behaviour.<br>
<br>
Thanks again<br>
<font color="#888888">Marcus<br>
</font><div><div></div><div class="Wj3C7c"><br>
<br>
On Mon, May 19, 2008 at 3:09 PM, Edson Tirelli &lt;<a href="mailto:tirelli@post.com">tirelli@post.com</a>&gt; wrote:<br>
&gt;<br>
&gt; &nbsp; &nbsp;All,<br>
&gt;<br>
&gt; &nbsp; &nbsp;I see that the code in that spot is weak and could be improved. Although,<br>
&gt; using drools 4.0.7, I successfully created a junit 4 test that I paste<br>
&gt; bellow. Also, the whole drools code is tested with junit 3 and we have no<br>
&gt; problems. For instance, look at our integration tests here:<br>
&gt;<br>
&gt; <a href="http://anonsvn.labs.jboss.com/labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/integrationtests/" target="_blank">http://anonsvn.labs.jboss.com/labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/integrationtests/</a><br>

&gt;<br>
&gt; &nbsp; &nbsp;The code I used to create the junit 4 test is based on the default<br>
&gt; example create by the drools plugin + the snippet you showed bellow:<br>
&gt;<br>
&gt; &nbsp; &nbsp; @Test<br>
&gt; &nbsp; &nbsp; public void testRuleBase() {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; try {<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //load up the rulebase<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RuleBase ruleBase = readRule();<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StatefulSession workingMemory = ruleBase.newStatefulSession();<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //go !<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Message message = new Message();<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message.setMessage( &nbsp;&quot;Hello World&quot; );<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message.setStatus( Message.HELLO );<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; workingMemory.insert( message );<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; workingMemory.fireAllRules();<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; workingMemory.dispose();<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; } catch (Throwable t) {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.printStackTrace();<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Assert.fail(&quot;Something is wrong: &quot;+t.getMessage());<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; }<br>
&gt; &nbsp; &nbsp; }<br>
&gt;<br>
&gt; &nbsp; &nbsp; /**<br>
&gt; &nbsp; &nbsp; &nbsp;* Please note that this is the &quot;low level&quot; rule assembly API.<br>
&gt; &nbsp; &nbsp; &nbsp;*/<br>
&gt; &nbsp; &nbsp; private RuleBase readRule() throws Exception {<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; //read in the source<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; Reader source = new InputStreamReader(<br>
&gt; DroolsTest.class.getResourceAsStream( &quot;/Sample.drl&quot; ) );<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; PackageBuilderConfiguration conf = new<br>
&gt; PackageBuilderConfiguration();<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; JavaDialectConfiguration javaConf = (JavaDialectConfiguration)<br>
&gt; conf.getDialectConfiguration(&quot;java&quot;);<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; javaConf.setCompiler(JavaDialectConfiguration.ECLIPSE);<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; javaConf.setJavaLanguageLevel(&quot;1.5&quot;);<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; PackageBuilder builder = new PackageBuilder( conf );<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; builder.addPackageFromDrl( source );<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; RuleBase ruleBase = RuleBaseFactory.newRuleBase();<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; ruleBase.addPackage( builder.getPackage() );<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; return ruleBase;<br>
&gt; &nbsp; &nbsp; }<br>
&gt;<br>
&gt; &nbsp; &nbsp; Hope it helps,<br>
&gt; &nbsp; &nbsp; &nbsp; Edson<br>
&gt;<br>
&gt;<br>
&gt; 2008/5/19 Marcus Ilgner &lt;<a href="mailto:marcus.ilgner@gmail.com">marcus.ilgner@gmail.com</a>&gt;:<br>
&gt;&gt;<br>
&gt;&gt; Hi list,<br>
&gt;&gt;<br>
&gt;&gt; I&#39;m reviving this thread because I happen to have the same problem.<br>
&gt;&gt;<br>
&gt;&gt; On Sun, Mar 23, 2008 at 7:34 PM, Mike Dean &lt;<a href="mailto:mdean77@comcast.net">mdean77@comcast.net</a>&gt; wrote:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Thanks (months later!). &nbsp;I have cut down my code example below to show<br>
&gt;&gt; &gt; this<br>
&gt;&gt; &gt; issue more clearly:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; John J. Franey wrote:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; NullPointerException on line 146 means classLoader is null. &nbsp; That is<br>
&gt;&gt; &gt;&gt; odd.<br>
&gt;&gt; &gt;&gt; I have no idea why the code that gets classLoader won&#39;t work in<br>
&gt;&gt; &gt;&gt; eclipse&#39;s<br>
&gt;&gt; &gt;&gt; junit runtime, but does when run in your eclipse plugin.<br>
&gt;&gt;<br>
&gt;&gt; &nbsp;It seems indeed like during JUnit tests, the context classloader of<br>
&gt;&gt; the thread gets not set (null).<br>
&gt;&gt;<br>
&gt;&gt; The code leading up to the problem is as follows:<br>
&gt;&gt; PackageBuilderConfiguration conf = new PackageBuilderConfiguration();<br>
&gt;&gt; JavaDialectConfiguration javaConf = (JavaDialectConfiguration)<br>
&gt;&gt; conf.getDialectConfiguration(&quot;java&quot;);<br>
&gt;&gt; javaConf.setCompiler(JavaDialectConfiguration.ECLIPSE);<br>
&gt;&gt; javaConf.setJavaLanguageLevel(&quot;1.5&quot;);<br>
&gt;&gt; RuleBase ruleBase = RuleBaseFactory.newRuleBase();<br>
&gt;&gt;<br>
&gt;&gt; The resulting stacktrace is:<br>
&gt;&gt; java.lang.NullPointerException<br>
&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;at<br>
&gt;&gt; org.drools.RuleBaseConfiguration.instantiateClass(RuleBaseConfiguration.java:569)<br>
&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;at<br>
&gt;&gt; org.drools.RuleBaseConfiguration.determineConsequenceExceptionHandler(RuleBaseConfiguration.java:561)<br>
&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;at<br>
&gt;&gt; org.drools.RuleBaseConfiguration.init(RuleBaseConfiguration.java:220)<br>
&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;at<br>
&gt;&gt; org.drools.RuleBaseConfiguration.&lt;init&gt;(RuleBaseConfiguration.java:133)<br>
&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;at<br>
&gt;&gt; org.drools.common.AbstractRuleBase.&lt;init&gt;(AbstractRuleBase.java:147)<br>
&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;at org.drools.reteoo.ReteooRuleBase.&lt;init&gt;(ReteooRuleBase.java:124)<br>
&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;at org.drools.reteoo.ReteooRuleBase.&lt;init&gt;(ReteooRuleBase.java:101)<br>
&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;at org.drools.RuleBaseFactory.newRuleBase(RuleBaseFactory.java:57)<br>
&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp;at org.drools.RuleBaseFactory.newRuleBase(RuleBaseFactory.java:38)<br>
&gt;&gt;<br>
&gt;&gt; Has anyone set up Drools and JUnit successfully? Maybe we forgot to<br>
&gt;&gt; set up the environment properly?<br>
&gt;&gt;<br>
&gt;&gt; Best regards<br>
&gt;&gt; Marcus<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> Office: +55 11 3529-6000<br> Mobile: +55 11 9287-5646<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a>