Plugin : use of instanceof

67 views
Skip to first unread message

Nicolas Micoud

unread,
Apr 4, 2015, 7:54:21 PM4/4/15
to idem...@googlegroups.com
Hi,

I've added a column on C_Invoice to store a value which is updated by different processes.
In those processes, as i didn't want to control update, i use X_C_Invoice instead of MInvoice.

And i was not able to save data. Log says :

java.lang.ClassCastException: org.compiere.model.X_C_Invoice cannot be cast to org.compiere.model.MInvoice
at org.globalqss.model.LCO_ValidatorWH.doHandleEvent(LCO_ValidatorWH.java:128)

this is the line :

if (po.get_TableName().equals(MInvoice.Table_Name) && type.equals(IEventTopics.PO_BEFORE_CHANGE)) {


I modify it to check if po is an MInvoice, and after this change, everything was ok
if (po instanceof MInvoice && po.get_TableName().equals(MInvoice.Table_Name) && type.equals(IEventTopics.PO_BEFORE_CHANGE)) {


So, now, i would like to ask if it could be considered as a good practice in plugin, to check if "po is instanceof M..."

WDYT ?

Thanks

Nicolas
Reply all
Reply to author
Forward
0 new messages