Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0036843Openbravo ERPA. Platformpublic2017-09-12 09:032017-09-22 08:35
alostale 
caristu 
normalmajorhave not tried
closedfixed 
5
 
3.0PR17Q2.43.0PR17Q2.4 
alostale
Core
No
0036843: jre8: js defaults containing Dates fail
When there is a default JavaScript value evaluated in server and it use JavaScript Date objects it fails when running in Java 8.
1. Open new Purchase Order Report
   -> ERROR:
      - Starting Date field is not defaulted (it should be default to today)
      - See openbravo.log:
ERROR org.openbravo.client.application.process.DefaultsProcessActionHandler - Error trying getting defaults and Filter Expressions for process: Cannot cast jdk.nashorn.internal.objects.NativeDate to java.util.Date
java.lang.ClassCastException: Cannot cast jdk.nashorn.internal.objects.NativeDate to java.util.Date
    at java.lang.invoke.MethodHandleImpl.newClassCastException(MethodHandleImpl.java:361)
    at java.lang.invoke.MethodHandleImpl.castReference(MethodHandleImpl.java:356)
    at jdk.nashorn.internal.scripts.Script$1$\^eval\_.:program(<eval>:1)
    at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:637)
    at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
    at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:449)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:406)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:402)
    at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
    at org.openbravo.client.application.ParameterUtils.getJSExpressionResult(ParameterUtils.java:281)
    at org.openbravo.client.application.ParameterUtils.getParameterDefaultValue(ParameterUtils.java:220)
In Java 8 JavaScript engine was changed from Rhino to Nashorn. JavaScript Dates evaluated in server, returned a java.util.Date in Rhino, but with Nashorn they are evaluated to jdk.nashorn.internal.objects.NativeDate. It will be necessary to implement proper casting (through reflection?) to support both Java 7 and 8.
No tags attached.
blocks defect 0036834 closed caristu jre8: js defaults containing Dates fail 
Issue History
2017-09-13 08:14alostaleTypedefect => backport
2017-09-13 08:14alostaleTarget Version => 3.0PR17Q2.4
2017-09-15 13:02hgbotCheckin
2017-09-15 13:02hgbotNote Added: 0099072
2017-09-15 13:02hgbotStatusscheduled => resolved
2017-09-15 13:02hgbotResolutionopen => fixed
2017-09-15 13:02hgbotFixed in SCM revision => http://code.openbravo.com/erp/backports/3.0PR17Q2.4/rev/02d89be55b5772f19e57d3eccd491c45e7619636 [^]
2017-09-15 13:03caristuReview Assigned To => alostale
2017-09-22 08:35alostaleStatusresolved => closed
2017-09-22 08:35alostaleFixed in Version => 3.0PR17Q2.4

Notes
(0099072)
hgbot   
2017-09-15 13:02   
Repository: erp/backports/3.0PR17Q2.4
Changeset: 02d89be55b5772f19e57d3eccd491c45e7619636
Author: Carlos Aristu <carlos.aristu <at> openbravo.com>
Date: Fri Sep 15 13:00:13 2017 +0200
URL: http://code.openbravo.com/erp/backports/3.0PR17Q2.4/rev/02d89be55b5772f19e57d3eccd491c45e7619636 [^]

fixes issue 36843: js defaults containing Dates fail in JRE8

In Java 8 JavaScript engine was changed from Rhino to Nashorn. JavaScript Dates evaluated in server, returned a java.util.Date in Rhino, but with Nashorn they are evaluated to jdk.nashorn.internal.objects.NativeDate.

This change caused a ClassCastException in JRE8 when invoking the methods of OBBindings which receive a java.util.Date as an argument. To fix the problem those methods have been overloaded by receiving an Object as argument. Therefore these methods will be invoked when working with JRE8, and we use reflection to retrieve the time information avoiding using classes which are not supported in JRE7.

---
M modules/org.openbravo.client.application/src/org/openbravo/client/application/OBBindings.java
---