"null" value is wrapped as Undefined.
Attila Szegedi
szegedia at gmail.com
Sat Jun 25 16:47:44 UTC 2022
I tried this little test program:
(function (y) { "x".contains(y) })()
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.
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.)
In the meantime, can you maybe change the signature of isBlank to take a String instead of a CharSequence? I think that’d work.
Attila.
> On 2022. Jun 23., at 17:01, Se Hee Lee <tosehee at gmail.com> wrote:
>
> It's Java
>
> public boolean isBlank(final CharSequence cs) {
> return StringUtils.isBlank(cs);
> }
>
> On Thu, Jun 23, 2022 at 4:45 AM Attila Szegedi <szegedia at gmail.com> wrote:
> Hi,
>
> 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?
>
> Thanks,
> Attila.
>
> > On 2022. Jun 6., at 19:17, Se Hee Lee <tosehee at gmail.com> wrote:
> >
> > Is there a way to prevent this automatic wrapping?
> >
> > In the following line, "oh.customAttribute4" is null, and it's passed into
> > isBlank() as "Undefined". And that triggers the ClassCastException. This
> > works fine in JDK 1.8.0_91, but fails in all future versions.
> >
> > Is there an optional parameter or flag that prevents this from
> > happening??????
> >
> > We have lots of rules that are based on 'nashorn' scripting engine, and we
> > cannot upgrade to future JDK due to this issue.
> >
> > if (oh.type == "Sales Order" && $S.isBlank(oh.customAttribute4) &&
> > oh.importType != "Transfer Order" && ol.item.customAttribute1 != "true" &&
> > $S.containsIgnoreCase(vars.highMovingItems, ol.item.number + ",") ||
> > $S.endsWithIgnoreCase(vars.highMovingItems, ol.item.number)) {
> >
> > Caused by: java.lang.ClassCastException: Cannot cast
> > org.openjdk.nashorn.internal.runtime.Undefined to java.lang.CharSequence
> >
> > --
> >
> >
> > Se Hee Lee / CTO
> > ------------------------------
> >
> > 11605 Haynes Bridge Rd, Suite 200 | Alpharetta, GA 30009
> > 470-214-3636 | slee at deposco.com | www.deposco.com
> > <https://deposco.com/?utm_source=Email%20Signature>
> >
> > [image: Twitter] <https://twitter.com/deposco> [image: Facebook]
> > <https://facebook.com/deposco> [image: Google +]
> > <https://plus.google.com/+Deposco> [image: LinkedIn]
> > <https://www.linkedin.com/company-beta/384437/>
> >
> > <https://deposco.com/?utm_source=Email%20Signature>
>
>
>
> --
> Se Hee Lee / CTO
> 11605 Haynes Bridge Rd, Suite 200 | Alpharetta, GA 30009
> 470-214-3636 | slee at deposco.com | www.deposco.com
>
>
>
>
>
More information about the nashorn-dev
mailing list