confirm instanceof on check parameter from web service
Description
Environment
Activity
Carlos Ruiz September 9, 2019 at 10:50 AM
Hi @Hiep Lq, agree that is unnecessary at this moment, but as the variable value is declared as an Object and not as a String, I think that bit of "defensive programming" doesn't hurt and protects in case somebody in future adds a different assignment to that Object.
Regards,
Carlos Ruiz
Hiep Lq August 31, 2019 at 7:38 AM
my code base is default branch, but it’s ok for release 6.2, this file hasn’t change.
my question about don’t need to check data type of variable “value”
line 553-558. value
always is String. don’t need to verify value instanceof BigDecimal
and value instanceof Integer
if (value instanceof BigDecimal)
bd = (BigDecimal)value;
else if (value instanceof Integer)
bd = new BigDecimal (((Integer)value).intValue());
else
bd = new BigDecimal (value.toString());
Deepak Pansheriya August 30, 2019 at 12:24 PMEdited
Hiep,
As per code in release 6.2, below is code block from line 493. And you can see that if Datafield is presents, it is immediately initialized.
String valueString = null;
DataField dataField = fmap.get( key );
if (dataField != null && !Util.isEmpty(dataField.getVal()))
{
valueString = dataField.getVal();
if (requestCtx != null && valueString.charAt(0) == '@')
{
Object value = ModelADServiceImpl.parseVariable(m_cs, requestCtx, iPara.getParameterName(), valueString);
valueString = value != null ? value.toString() : null;
}
}
else if (dataField != null && !Util.isEmpty(dataField.getLval()))
valueString = getLookupValue(pPara, dataField);
It sounds I may not understanding your questions.
Deepak Pansheriya August 30, 2019 at 11:47 AM
@hiep Please mention which revision are you referring as I an bit abke ti find line 513 code in release 6.2
org.idempiere.adinterface.Process.fillParameter
line 498 String valueString = null; line 513 Object value = valueString; util line 512, value isn't to any value other null so check instanceof isn't valuable. true? BigDecimal bd = null; if (value instanceof BigDecimal) bd = (BigDecimal)value; else if (value instanceof Integer) bd = new BigDecimal (((Integer)value).intValue()); else bd = new BigDecimal (value.toString());
@Deepak Pansheriya WDYT?