<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">What you are running into is a change where Nashorn used to treat any java.lang.Number implementation as a JavaScript number type, but later became more strict and only considers those built-in number types that can be represented by a double without loss as a number. This is due to the fact that in JavaScript, numbers are always 64-bit floating-point values (that is, doubles.) Nashorn even used to have a special-cased support for longs for a while, but even that was removed as long is also incompatible with double as a double can only accurately represent a long with a magnitude up to 53 bits.<div class=""><br class=""></div><div class="">If you evaluate:</div><div class=""> typeof(new java.math.BigInteger("1”))</div><div class="">you’ll get “number” on Java 8 and “object” on Java 11. Same would happen for e.g. new java.lang.Long(0): number on Java 8, object on Java 11.</div><div class=""><div class=""><br class=""></div><div class="">Given how this change occurred somewhere in Java 9 timeframe (released in September 2017), you’re facing a backwards compatibility issue that is half a decade old. It would be unlikely to be addressed even if it were simply a bug, but it was, in fact, a conscious design decision back in the day.</div><div class=""><br class=""></div><div class="">Since BigInteger is treated just like any JavaScript object, the abstract equality comparison operator’s step 1.f. applies (see <a href="https://es5.github.io/#x11.9.3" class="">https://es5.github.io/#x11.9.3</a>) as they are both evaluated to be of type Object, not Number.</div><div class=""><br class=""></div><div class="">Sorry, but I don’t have better news for you than that you’ll have to change your code somehow in the migration. You can still invoke .equals() method on them, for instance:</div><div class=""><br class=""></div><div class=""><div class="">jjs> var x = new java.math.BigInteger("1")</div><div class="">jjs> var y = new java.math.BigInteger("1")</div><div class="">jjs> x == y</div><div class="">false</div><div class="">jjs> x.equals(y)</div><div class="">true</div></div><div class=""><br class=""></div><div class="">On an unrelated note, I wanted to point that your examples are also wrong in that in Nashorn you can’t use () operator to get/set map elements. You can however use [] operator for that purpose.</div><div class=""><br class=""></div><div class="">Attila.</div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 2022. Aug 9., at 22:06, Se Hee Lee <<a href="mailto:tosehee@gmail.com" class="">tosehee@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Slightly wrong information.<div class=""><br class=""></div><div class=""><div class="">ar map = new HashMap();</div><div class="">map("foo") = new BigInteger('1");</div><div class="">map("bar") = new BigInteger("1");</div><div class=""><br class=""></div><div class="">if (map("foo") == map("bar")) {</div><div class="">....}</div></div><div class=""><br class=""></div><div class="">In Java 1.8.0_91, it evaluates to "true", but in anything above that version, it evaluates to false.....</div><div class=""><br class=""></div><div class="">Technically speaking, I understand that it should be "false", but we have millions of rules that simply returns the numeric value from database (normally returns as BigInteger or Long) and above comparison simply because 1.8.0_91 ALLOWED it.</div><div class=""><br class=""></div><div class="">Now we are trying to upgrade to Java 17 with stand-alone nashorn lib, but we can't due to these incompatibility issues...</div><div class=""><br class=""></div><div class="">If anyone can point me a direction as to what needs to be modified, we can do that in-house.. </div><div class=""><br class=""></div><div class="">Any help is greatly appreciated. We really want to upgrade our apps....!</div><div class=""><br class=""></div><div class=""><br class=""></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 9, 2022 at 2:36 PM Se Hee Lee <<a href="mailto:tosehee@gmail.com" class="">tosehee@gmail.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr" class="">Hey Attila. Not sure where you are with the fix... Any update is really appreciated.<div class=""><br class=""></div><div class="">In addition, we found another compatibility issue with nashorn in Java 8 vs stand alone nashorn lib.</div><div class=""><br class=""></div><div class="">var map = new HashMap();</div><div class="">map("foo") = 1;</div><div class=""><br class=""></div><div class="">if (map("foo") == 1) {</div><div class="">....}</div><div class=""><br class=""></div><div class="">Above "If" condition evaluates to "true" in Java 8, but it's evaluating to "false" in stand-alone nashorn lib.</div><div class=""><br class=""></div><div class="">I am guessing map("foo") holds "java.lang.Integer, and autoboxing is not working correctly.</div><div class=""><br class=""></div><div class="">This is actually bigger issue as we now have the rules that are evaluating incorrectly. At least with the previous issue, we got an error and we can workaround. This is serious compatibility issue.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jun 25, 2022 at 12:53 PM Se Hee Lee <<a href="mailto:tosehee@gmail.com" target="_blank" class="">tosehee@gmail.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto" class="">Yes we can upgrade to 11</div><div class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jun 25, 2022 at 12:47 PM Attila Szegedi <<a href="mailto:szegedia@gmail.com" target="_blank" class="">szegedia@gmail.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I tried this little test program:<br class="">
<br class="">
(function (y) { "x".contains(y) })()<br class="">
<br class="">
and it fails for me even on 1.8.0_91-b14 with ClassCastException. Arguably, since undefined is converted to “undefined” string when the target type is String, it would make sense for it to work with CharSequence too.<br class="">
<br class="">
Bad news is that I can fix this for standalone Nashorn, but you will have to upgrade to at least Java 11 to take advantage of it. (Also, I need to publish the fix too so it too might take few days.)<br class="">
<br class="">
In the meantime, can you maybe change the signature of isBlank to take a String instead of a CharSequence? I think that’d work.<br class="">
<br class="">
Attila.<br class="">
<br class="">
> On 2022. Jun 23., at 17:01, Se Hee Lee <<a href="mailto:tosehee@gmail.com" target="_blank" class="">tosehee@gmail.com</a>> wrote:<br class="">
> <br class="">
> It's Java<br class="">
> <br class="">
> public boolean isBlank(final CharSequence cs) {<br class="">
> return StringUtils.isBlank(cs);<br class="">
> }<br class="">
> <br class="">
> On Thu, Jun 23, 2022 at 4:45 AM Attila Szegedi <<a href="mailto:szegedia@gmail.com" target="_blank" class="">szegedia@gmail.com</a>> wrote:<br class="">
> Hi,<br class="">
> <br class="">
> I’d like to look into this, but can you tell me how is “$S.isBlank” defined? If it is in Java, what is its method signature?<br class="">
> <br class="">
> Thanks,<br class="">
> Attila.<br class="">
> <br class="">
> > On 2022. Jun 6., at 19:17, Se Hee Lee <<a href="mailto:tosehee@gmail.com" target="_blank" class="">tosehee@gmail.com</a>> wrote:<br class="">
> > <br class="">
> > Is there a way to prevent this automatic wrapping?<br class="">
> > <br class="">
> > In the following line, "oh.customAttribute4" is null, and it's passed into<br class="">
> > isBlank() as "Undefined". And that triggers the ClassCastException. This<br class="">
> > works fine in JDK 1.8.0_91, but fails in all future versions.<br class="">
> > <br class="">
> > Is there an optional parameter or flag that prevents this from<br class="">
> > happening??????<br class="">
> > <br class="">
> > We have lots of rules that are based on 'nashorn' scripting engine, and we<br class="">
> > cannot upgrade to future JDK due to this issue.<br class="">
> > <br class="">
> > if (oh.type == "Sales Order" && $S.isBlank(oh.customAttribute4) &&<br class="">
> > oh.importType != "Transfer Order" && ol.item.customAttribute1 != "true" &&<br class="">
> > $S.containsIgnoreCase(vars.highMovingItems, ol.item.number + ",") ||<br class="">
> > $S.endsWithIgnoreCase(vars.highMovingItems, ol.item.number)) {<br class="">
> > <br class="">
> > Caused by: java.lang.ClassCastException: Cannot cast<br class="">
> > org.openjdk.nashorn.internal.runtime.Undefined to java.lang.CharSequence<br class="">
> > <br class="">
> > --<br class="">
> > <br class="">
> > <br class="">
> > Se Hee Lee / CTO<br class="">
> > ------------------------------<br class="">
> > <br class="">
> > 11605 Haynes Bridge Rd, Suite 200 | Alpharetta, GA 30009<br class="">
> > 470-214-3636 | <a href="mailto:slee@deposco.com" target="_blank" class="">slee@deposco.com</a> | <a href="http://www.deposco.com/" rel="noreferrer" target="_blank" class="">www.deposco.com</a><br class="">
> > <<a href="https://deposco.com/?utm_source=Email%20Signature" rel="noreferrer" target="_blank" class="">https://deposco.com/?utm_source=Email%20Signature</a>><br class="">
> > <br class="">
> > [image: Twitter] <<a href="https://twitter.com/deposco" rel="noreferrer" target="_blank" class="">https://twitter.com/deposco</a>> [image: Facebook]<br class="">
> > <<a href="https://facebook.com/deposco" rel="noreferrer" target="_blank" class="">https://facebook.com/deposco</a>> [image: Google +]<br class="">
> > <<a href="https://plus.google.com/+Deposco" rel="noreferrer" target="_blank" class="">https://plus.google.com/+Deposco</a>> [image: LinkedIn]<br class="">
> > <<a href="https://www.linkedin.com/company-beta/384437/" rel="noreferrer" target="_blank" class="">https://www.linkedin.com/company-beta/384437/</a>><br class="">
> > <br class="">
> > <<a href="https://deposco.com/?utm_source=Email%20Signature" rel="noreferrer" target="_blank" class="">https://deposco.com/?utm_source=Email%20Signature</a>><br class="">
> <br class="">
> <br class="">
> <br class="">
> -- <br class="">
> Se Hee Lee / CTO<br class="">
> 11605 Haynes Bridge Rd, Suite 200 | Alpharetta, GA 30009 <br class="">
> 470-214-3636 | <a href="mailto:slee@deposco.com" target="_blank" class="">slee@deposco.com</a> | <a href="http://www.deposco.com/" rel="noreferrer" target="_blank" class="">www.deposco.com</a> <br class="">
> <br class="">
> <br class="">
> <br class="">
> <br class="">
> <br class="">
<br class="">
</blockquote></div></div>-- <br class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><pre class=""><div style="font-family:Arial;white-space:normal;color:rgb(136,136,136);font-size:12px" class=""><table cellspacing="0" cellpadding="0" dir="ltr" style="border-collapse:collapse;color:rgb(41,43,44);font-family:GothamBook;font-size:16px" class=""><tbody class=""><tr class=""><td class=""><blockquote style="margin:0px;padding-left:0ex" class=""><div style="margin-top: 0px; margin-bottom: 0px; font-family: Arial; font-size: 18px; line-height: 20px; color: rgb(33, 33, 33);" class=""><span style="font-weight:bold" class="">Se Hee Lee / CTO</span></div><hr style="height:0px;overflow:visible;margin:10px 0px;border-right:none;border-bottom-style:solid;border-bottom-color:rgb(229,229,229);border-left:none;border-top:none;width:300px" class=""><p style="margin-top:0px;margin-bottom:10px;font-family:Arial;font-size:10px;line-height:14px" class=""><span style="color:rgb(153,153,153)" class="">11605 Haynes Bridge Rd, Suite 200 | Alpharetta, GA 30009</span> <br class=""><a href="tel:470-214-3636" style="background-color:transparent;color:rgb(33,33,33);display:inline" target="_blank" class="">470-214-3636</a> | <a href="mailto:slee@deposco.com" style="background-color:transparent;color:rgb(33,33,33);display:inline" target="_blank" class="">slee@deposco.com</a> | <a href="https://deposco.com/?utm_source=Email%20Signature" style="background-color:transparent;color:rgb(33,33,33);display:inline" target="_blank" class="">www.deposco.com</a> <br class=""></p><p style="margin-top:0px;margin-bottom:10px;font-size:0px;line-height:0;font-family:Arial" class=""><a href="https://twitter.com/deposco" style="background-color:transparent;color:rgb(244,128,32);display:inline" target="_blank" class=""><img width="16" height="16" src="http://staff.deposco.com/img/twitter-icon.png" alt="Twitter" style="border: none; vertical-align: middle; margin-bottom: 2px; display: inline;" class=""> </a><span style="white-space:nowrap" class=""><img src="http://staff.deposco.com/img/spacer.gif" width="3" style="border-style: none; vertical-align: middle;" class=""> </span><a href="https://facebook.com/deposco" style="background-color:transparent;color:rgb(244,128,32);display:inline" target="_blank" class=""><img width="16" height="16" src="http://staff.deposco.com/img/facebook-icon.png" alt="Facebook" style="border: none; vertical-align: middle; margin-bottom: 2px; display: inline;" class=""> </a><span style="white-space:nowrap" class=""><img src="http://staff.deposco.com/img/spacer.gif" width="3" style="border-style: none; vertical-align: middle;" class=""> </span><a href="https://plus.google.com/+Deposco" style="background-color:transparent;color:rgb(244,128,32);display:inline" target="_blank" class=""><img width="16" height="16" src="http://staff.deposco.com/img/google-icon.png" alt="Google +" style="border: none; vertical-align: middle; margin-bottom: 2px; display: inline;" class=""> </a><span style="white-space:nowrap" class=""><img src="http://staff.deposco.com/img/spacer.gif" width="3" style="border-style: none; vertical-align: middle;" class=""> </span><a href="https://www.linkedin.com/company-beta/384437/" style="background-color:transparent;color:rgb(244,128,32);display:inline" target="_blank" class=""><img width="16" height="16" src="http://staff.deposco.com/img/linkedin-icon.png" alt="LinkedIn" style="border: none; vertical-align: middle; margin-bottom: 2px; display: inline;" class=""> </a><span style="white-space:nowrap" class=""><img src="http://staff.deposco.com/img/spacer.gif" width="3" style="border-style: none; vertical-align: middle;" class=""></span></p></blockquote></td></tr><tr class=""><td class=""><fieldset style="border-width:0px;border-style:initial;border-color:initial;margin:0px;padding:0px;min-width:0px" class=""><a href="https://deposco.com/?utm_source=Email%20Signature" style="background-color:transparent;color:rgb(33,33,33);display:inline" target="_blank" class=""><img src="http://staff.deposco.com/img/email-signature-cta.gif" width="300" height="69" style="border-style: none; vertical-align: middle; border-radius: 0px; width: 300px; height: 69px; max-width: 300px;" class=""></a></fieldset></td></tr></tbody></table><br class=""></div></pre></div></div></div></div>
</blockquote></div><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><pre class=""><div style="font-family:Arial;white-space:normal;color:rgb(136,136,136);font-size:12px" class=""><table cellspacing="0" cellpadding="0" dir="ltr" style="border-collapse:collapse;color:rgb(41,43,44);font-family:GothamBook;font-size:16px" class=""><tbody class=""><tr class=""><td class=""><blockquote style="margin:0px;padding-left:0ex" class=""><div style="margin-top: 0px; margin-bottom: 0px; font-family: Arial; font-size: 18px; line-height: 20px; color: rgb(33, 33, 33);" class=""><span style="font-weight:bold" class="">Se Hee Lee / CTO</span></div><hr style="height:0px;overflow:visible;margin:10px 0px;border-right:none;border-bottom-style:solid;border-bottom-color:rgb(229,229,229);border-left:none;border-top:none;width:300px" class=""><p style="margin-top:0px;margin-bottom:10px;font-family:Arial;font-size:10px;line-height:14px" class=""><span style="color:rgb(153,153,153)" class="">11605 Haynes Bridge Rd, Suite 200 | Alpharetta, GA 30009</span> <br class=""><a href="tel:470-214-3636" style="background-color:transparent;color:rgb(33,33,33);display:inline" target="_blank" class="">470-214-3636</a> | <a href="mailto:slee@deposco.com" style="background-color:transparent;color:rgb(33,33,33);display:inline" target="_blank" class="">slee@deposco.com</a> | <a href="https://deposco.com/?utm_source=Email%20Signature" style="background-color:transparent;color:rgb(33,33,33);display:inline" target="_blank" class="">www.deposco.com</a> <br class=""></p><p style="margin-top:0px;margin-bottom:10px;font-size:0px;line-height:0;font-family:Arial" class=""><a href="https://twitter.com/deposco" style="background-color:transparent;color:rgb(244,128,32);display:inline" target="_blank" class=""><img width="16" height="16" src="http://staff.deposco.com/img/twitter-icon.png" alt="Twitter" style="border: none; vertical-align: middle; margin-bottom: 2px; display: inline;" class=""> </a><span style="white-space:nowrap" class=""><img src="http://staff.deposco.com/img/spacer.gif" width="3" style="border-style: none; vertical-align: middle;" class=""> </span><a href="https://facebook.com/deposco" style="background-color:transparent;color:rgb(244,128,32);display:inline" target="_blank" class=""><img width="16" height="16" src="http://staff.deposco.com/img/facebook-icon.png" alt="Facebook" style="border: none; vertical-align: middle; margin-bottom: 2px; display: inline;" class=""> </a><span style="white-space:nowrap" class=""><img src="http://staff.deposco.com/img/spacer.gif" width="3" style="border-style: none; vertical-align: middle;" class=""> </span><a href="https://plus.google.com/+Deposco" style="background-color:transparent;color:rgb(244,128,32);display:inline" target="_blank" class=""><img width="16" height="16" src="http://staff.deposco.com/img/google-icon.png" alt="Google +" style="border: none; vertical-align: middle; margin-bottom: 2px; display: inline;" class=""> </a><span style="white-space:nowrap" class=""><img src="http://staff.deposco.com/img/spacer.gif" width="3" style="border-style: none; vertical-align: middle;" class=""> </span><a href="https://www.linkedin.com/company-beta/384437/" style="background-color:transparent;color:rgb(244,128,32);display:inline" target="_blank" class=""><img width="16" height="16" src="http://staff.deposco.com/img/linkedin-icon.png" alt="LinkedIn" style="border: none; vertical-align: middle; margin-bottom: 2px; display: inline;" class=""> </a><span style="white-space:nowrap" class=""><img src="http://staff.deposco.com/img/spacer.gif" width="3" style="border-style: none; vertical-align: middle;" class=""></span></p></blockquote></td></tr><tr class=""><td class=""><fieldset style="border-width:0px;border-style:initial;border-color:initial;margin:0px;padding:0px;min-width:0px" class=""><a href="https://deposco.com/?utm_source=Email%20Signature" style="background-color:transparent;color:rgb(33,33,33);display:inline" target="_blank" class=""><img src="http://staff.deposco.com/img/email-signature-cta.gif" width="300" height="69" style="border-style: none; vertical-align: middle; border-radius: 0px; width: 300px; height: 69px; max-width: 300px;" class=""></a></fieldset></td></tr></tbody></table><br class=""></div></pre></div></div></div></div>
</blockquote></div><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class="gmail_signature"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><pre class=""><div style="font-family:Arial;white-space:normal;color:rgb(136,136,136);font-size:12px" class=""><table cellspacing="0" cellpadding="0" dir="ltr" style="border-collapse:collapse;color:rgb(41,43,44);font-family:GothamBook;font-size:16px" class=""><tbody class=""><tr class=""><td class=""><blockquote style="margin:0px;padding-left:0ex" class=""><div style="margin-top: 0px; margin-bottom: 0px; font-family: Arial; font-size: 18px; line-height: 20px; color: rgb(33, 33, 33);" class=""><span style="font-weight:bold" class="">Se Hee Lee / CTO</span></div><hr style="height:0px;overflow:visible;margin:10px 0px;border-right:none;border-bottom-style:solid;border-bottom-color:rgb(229,229,229);border-left:none;border-top:none;width:300px" class=""><p style="margin-top:0px;margin-bottom:10px;font-family:Arial;font-size:10px;line-height:14px" class=""><span style="color:rgb(153,153,153)" class="">11605 Haynes Bridge Rd, Suite 200 | Alpharetta, GA 30009</span> <br class=""><a href="tel:470-214-3636" style="background-color:transparent;color:rgb(33,33,33);display:inline" target="_blank" class="">470-214-3636</a> | <a href="mailto:slee@deposco.com" style="background-color:transparent;color:rgb(33,33,33);display:inline" target="_blank" class="">slee@deposco.com</a> | <a href="https://deposco.com/?utm_source=Email%20Signature" style="background-color:transparent;color:rgb(33,33,33);display:inline" target="_blank" class="">www.deposco.com</a> <br class=""></p><p style="margin-top:0px;margin-bottom:10px;font-size:0px;line-height:0;font-family:Arial" class=""><a href="https://twitter.com/deposco" style="background-color:transparent;color:rgb(244,128,32);display:inline" target="_blank" class=""><img width="16" height="16" src="http://staff.deposco.com/img/twitter-icon.png" alt="Twitter" style="border: none; vertical-align: middle; margin-bottom: 2px; display: inline;" class=""> </a><span style="white-space:nowrap" class=""><img src="http://staff.deposco.com/img/spacer.gif" width="3" style="border-style: none; vertical-align: middle;" class=""> </span><a href="https://facebook.com/deposco" style="background-color:transparent;color:rgb(244,128,32);display:inline" target="_blank" class=""><img width="16" height="16" src="http://staff.deposco.com/img/facebook-icon.png" alt="Facebook" style="border: none; vertical-align: middle; margin-bottom: 2px; display: inline;" class=""> </a><span style="white-space:nowrap" class=""><img src="http://staff.deposco.com/img/spacer.gif" width="3" style="border-style: none; vertical-align: middle;" class=""> </span><a href="https://plus.google.com/+Deposco" style="background-color:transparent;color:rgb(244,128,32);display:inline" target="_blank" class=""><img width="16" height="16" src="http://staff.deposco.com/img/google-icon.png" alt="Google +" style="border: none; vertical-align: middle; margin-bottom: 2px; display: inline;" class=""> </a><span style="white-space:nowrap" class=""><img src="http://staff.deposco.com/img/spacer.gif" width="3" style="border-style: none; vertical-align: middle;" class=""> </span><a href="https://www.linkedin.com/company-beta/384437/" style="background-color:transparent;color:rgb(244,128,32);display:inline" target="_blank" class=""><img width="16" height="16" src="http://staff.deposco.com/img/linkedin-icon.png" alt="LinkedIn" style="border: none; vertical-align: middle; margin-bottom: 2px; display: inline;" class=""> </a><span style="white-space:nowrap" class=""><img src="http://staff.deposco.com/img/spacer.gif" width="3" style="border-style: none; vertical-align: middle;" class=""></span></p></blockquote></td></tr><tr class=""><td class=""><fieldset style="border-width:0px;border-style:initial;border-color:initial;margin:0px;padding:0px;min-width:0px" class=""><a href="https://deposco.com/?utm_source=Email%20Signature" style="background-color:transparent;color:rgb(33,33,33);display:inline" target="_blank" class=""><img src="http://staff.deposco.com/img/email-signature-cta.gif" width="300" height="69" style="border-style: none; vertical-align: middle; border-radius: 0px; width: 300px; height: 69px; max-width: 300px;" class=""></a></fieldset></td></tr></tbody></table><br class=""></div></pre></div></div></div></div>
</div></blockquote></div><br class=""></div></div></body></html>