From e14cfc212a3d493756e7de023342a71a76b58d29 Mon Sep 17 00:00:00 2001 From: Elaine Tan Date: Thu, 4 Apr 2013 16:26:44 +0800 Subject: [PATCH] Handle NPE when no datarow is provided in queryData request --- .../adinterface/ModelADServiceImpl.java | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/ModelADServiceImpl.java b/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/ModelADServiceImpl.java index e90e82b858..00490463d6 100644 --- a/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/ModelADServiceImpl.java +++ b/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/ModelADServiceImpl.java @@ -1384,14 +1384,17 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic String sqlquery = "SELECT * FROM " + tableName; sqlquery = role.addAccessSQL(sqlquery, tableName, true, true); - for (DataField field : modelCRUD.getDataRow().getFieldArray()) { - if (m_webservicetype.isInputColumnNameAllowed(field.getColumn())) { - sqlquery += " AND " + field.getColumn() + "=?"; - } else { - throw new IdempiereServiceFault("Web service type " - + m_webservicetype.getValue() + ": input column " - + field.getColumn() + " not allowed", new QName("queryData")); - } + if (modelCRUD.getDataRow() != null) + { + for (DataField field : modelCRUD.getDataRow().getFieldArray()) { + if (m_webservicetype.isInputColumnNameAllowed(field.getColumn())) { + sqlquery += " AND " + field.getColumn() + "=?"; + } else { + throw new IdempiereServiceFault("Web service type " + + m_webservicetype.getValue() + ": input column " + + field.getColumn() + " not allowed", new QName("queryData")); + } + } } if (modelCRUD.getFilter() != null && modelCRUD.getFilter().length() > 0) @@ -1406,15 +1409,18 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic { pstmtquery = DB.prepareStatement (sqlquery, null); int p = 1; - for (DataField field : modelCRUD.getDataRow().getFieldArray()) { - int idx = poinfo.getColumnIndex(field.getColumn()); - Class c = poinfo.getColumnClass(idx); - if (c == Integer.class) - pstmtquery.setInt(p++, Integer.valueOf(field.getVal())); - else if (c == Timestamp.class) - pstmtquery.setTimestamp(p++, Timestamp.valueOf(field.getVal())); - else if (c == Boolean.class || c == String.class) - pstmtquery.setString(p++, field.getVal()); + if (modelCRUD.getDataRow() != null) + { + for (DataField field : modelCRUD.getDataRow().getFieldArray()) { + int idx = poinfo.getColumnIndex(field.getColumn()); + Class c = poinfo.getColumnClass(idx); + if (c == Integer.class) + pstmtquery.setInt(p++, Integer.valueOf(field.getVal())); + else if (c == Timestamp.class) + pstmtquery.setTimestamp(p++, Timestamp.valueOf(field.getVal())); + else if (c == Boolean.class || c == String.class) + pstmtquery.setString(p++, field.getVal()); + } } rsquery = pstmtquery.executeQuery (); // Angelo Dabala' (genied) must create just one DataSet, moved outside of the while loop