Hi Senthalan,
Does this means we have to change our existing custom functions to the same
pattern to define it as a "var" ?

I am wondering why the previous way of defining functions fails in java 11.

Cheers,
Ruwan A


On Fri, Sep 27, 2019 at 3:03 PM Senthalan Kanagalingam <[email protected]>
wrote:

> Hi all,
>
> When running the age-based authentication script[1] in wso2 server 5.9.0
> beta, we faced the following error,
>
> Exception :
>
> <eval>:8 TypeError: null is not a function
>       at 
> jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)
>       at 
> jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:213)
>       at 
> jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:185)
>       at 
> jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:172)
>       at 
> jdk.scripting.nashorn/jdk.nashorn.internal.runtime.linker.NashornBottomLinker.linkNull(NashornBottomLinker.java:251)
>       at 
> jdk.scripting.nashorn/jdk.nashorn.internal.runtime.linker.NashornBottomLinker.getGuardedInvocation(NashornBottomLinker.java:71)
>       at 
> jdk.dynalink/jdk.dynalink.linker.support.CompositeGuardingDynamicLinker.getGuardedInvocation(CompositeGuardingDynamicLinker.java:109)
>       at 
> jdk.dynalink/jdk.dynalink.LinkerServicesImpl.lambda$getGuardedInvocation$0(LinkerServicesImpl.java:137)
>       at 
> jdk.dynalink/jdk.dynalink.LinkerServicesImpl.getWithLookupInternal(LinkerServicesImpl.java:168)
>       at 
> jdk.dynalink/jdk.dynalink.LinkerServicesImpl.getGuardedInvocation(LinkerServicesImpl.java:135)
>       at 
> jdk.dynalink/jdk.dynalink.DynamicLinker.relink(DynamicLinker.java:242)
>       at 
> jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$97$\^eval\_$cu1$restOf.L:1(<eval>:8)
>       at 
> jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:657)
>       at 
> jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513)
>       at 
> jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:527)
>       at 
> jdk.scripting.nashorn/jdk.nashorn.api.scripting.ScriptObjectMirror.call(ScriptObjectMirror.java:120)
>       at 
> org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.GraphBasedSequenceHandler.lambda$executeFunction$1(GraphBasedSequenceHandler.java:616)
>       at 
> org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilder$JsBasedEvaluator.evaluate(JsGraphBuilder.java:881)
>       at 
> org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.GraphBasedSequenceHandler.executeFunction(GraphBasedSequenceHandler.java:616)
>       at 
> org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.GraphBasedSequenceHandler.handleDecisionPoint(GraphBasedSequenceHandler.java:578)
>       at 
> org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.GraphBasedSequenceHandler.handleNode(GraphBasedSequenceHandler.java:170)
>       at 
> org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.GraphBasedSequenceHandler.handle(GraphBasedSequenceHandler.java:127)
>       at 
> org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.DefaultAuthenticationRequestHandler.handle(DefaultAuthenticationRequestHandler.java:142)
>       at 
> org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.DefaultRequestCoordinator.handle(DefaultRequestCoordinator.java:239)
>       at 
> org.wso2.carbon.identity.application.authentication.framework.CommonAuthenticationHandler.doPost(CommonAuthenticationHandler.java:46)
>
>
> When analysing we found that the issue with the following method signature,
>
> function getAge(birthDate) {
>     var today = new Date();
>     var age = today.getFullYear() - birthDate.getFullYear();
>     var m = today.getMonth() - birthDate.getMonth();
>     if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
>         age--;
>     }
>     return age;
> }
>
> when this changed to,
> var getAge = function (birthDate) {
>     var today = new Date();
>     var age = today.getFullYear() - birthDate.getFullYear();
>     var m = today.getMonth() - birthDate.getMonth();
>     if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
>         age--;
>     }
>     return age;
> };
>
> Then the authentication script worked. And this method signature format
> worked in java 8 as well. So we have changed our default templates in 5.9.0
> to java 11 by default.
>
> To make consistency in the script, we decided to change the onLoginRequest
> as well to the new method signature. (The existing onLoginRequest method
> signature will work with java 11)
>
> So the existing developers who decide to use java 11 with IS 5.9.0 have to
> change the method signature. But if developers continue with java 8. There
> won't be any changes needed. Please raise if you have any concerns.
>
> [1] -
> https://docs.wso2.com/display/IS580/Configuring+User-Age-Based+Adaptive+Authentication
>
> Thanks,
> Senthalan
> --
> Senthalan Kanagalingam | Senior Software Engineer | WSO2 Inc.
> (m) +94 (0) 77 18 77 466 | (w) +94117435800 | (e) [email protected]
>
> <http://wso2.com/signature>
>
>

-- 
Ruwan Abeykoon | Director/Architect | WSO2 Inc.
(w) +947435800  | Email: [email protected]
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to