<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
On 28/07/2011 08:26, bolsover wrote:
<blockquote cite="mid:1311837997813-3205961.post@n3.nabble.com"
type="cite">
<pre wrap="">Mark
Thanks for the info - although it was not actually the solution to my
problem, it prompted me to look again at my assertion that there were not
any null values. In actual fact answerData[0] was null ( I should have been
checking for answerData[100]) and this was causing the error.
You modified syntax is much tidier; I'm now using the following format:
$a : Answer(answerData[0] != null && answerData[0].value_str == "Valves") </pre>
</blockquote>
I'm not sure it's supported in our parser, but I think we should do
it - either add support for it, or make it implement to the "."
accessor. MVEL supports null safe navigation, which means it'll
return false if a null value is returned from an accessor.<br>
<a class="moz-txt-link-freetext" href="http://mvel.codehaus.org/MVEL+2.0+Property+Navigation">http://mvel.codehaus.org/MVEL+2.0+Property+Navigation</a><br>
<p>"Sometimes you have property expressions which may contain a null
element, requiring you to create a null-check. You can simplify
this by using the null-safe operator:</p>
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-java">user.?manager.name
</pre>
</div>
</div>
<p>This is functionally equivalent to writing: </p>
<div class="code panel" style="border-width: 1px;">
<div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">if</span> (user.manager != <span class="code-keyword">null</span>) { <span class="code-keyword">return</span> user.manager.name; } <span class="code-keyword">else</span> { <span class="code-keyword">return</span> <span class="code-keyword">null</span>; }"
</pre>
</div>
</div>
<br>
<br>
I doubt there is a time when someone wants a nullpointer to happen.
So maybe we should build this in as default into expressions. I
guess the only time we shouldn't is if people know it will enver be
null and don't want the small overad for the null check.<br>
<br>
What do people think?<br>
<br>
Mark<br>
<blockquote cite="mid:1311837997813-3205961.post@n3.nabble.com"
type="cite">
<pre wrap="">
This prevents the prior null pointer exception.
Thanks for your input.
David
--
View this message in context: <a class="moz-txt-link-freetext" href="http://drools.46999.n3.nabble.com/Condition-syntax-to-access-Map-tp3204429p3205961.html">http://drools.46999.n3.nabble.com/Condition-syntax-to-access-Map-tp3204429p3205961.html</a>
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
</blockquote>
<br>
</body>
</html>