IDEMPIERE-455 Discover and fix FindBugs problems / Pattern NP_NULL_ON_SOME_PATH (Thanks to Richard Morales)

This commit is contained in:
Carlos Ruiz 2012-12-12 16:30:06 -05:00
parent e652439bc0
commit 24e4972406
22 changed files with 60 additions and 44 deletions

View File

@ -284,10 +284,12 @@ public abstract class AbstractDocumentSearch {
} }
} }
} }
log.fine(whereString.toString());
final MQuery query = new MQuery(tableName); final MQuery query = new MQuery(tableName);
query.addRestriction(whereString.toString()); if (whereString != null) {
log.fine(whereString.toString());
query.addRestriction(whereString.toString());
}
final boolean ok = openWindow(windowId, query); final boolean ok = openWindow(windowId, query);
if (!ok) { if (!ok) {
StringBuilder msglog = new StringBuilder("Unable to open window: ").append(whereString.toString()); StringBuilder msglog = new StringBuilder("Unable to open window: ").append(whereString.toString());

View File

@ -207,6 +207,7 @@ public class Doc_MatchPO extends Doc
FactLine cr = fact.createLine(null, FactLine cr = fact.createLine(null,
m_pc.getAccount(ProductCost.ACCTTYPE_P_PPV, as), m_pc.getAccount(ProductCost.ACCTTYPE_P_PPV, as),
as.getC_Currency_ID(), isReturnTrx ? difference.negate() : difference); as.getC_Currency_ID(), isReturnTrx ? difference.negate() : difference);
MAccount acct_cr = null;
if (cr != null) if (cr != null)
{ {
cr.setQty(isReturnTrx ? getQty().negate() : getQty()); cr.setQty(isReturnTrx ? getQty().negate() : getQty());
@ -219,12 +220,14 @@ public class Doc_MatchPO extends Doc
cr.setC_UOM_ID(m_oLine.getC_UOM_ID()); cr.setC_UOM_ID(m_oLine.getC_UOM_ID());
cr.setUser1_ID(m_oLine.getUser1_ID()); cr.setUser1_ID(m_oLine.getUser1_ID());
cr.setUser2_ID(m_oLine.getUser2_ID()); cr.setUser2_ID(m_oLine.getUser2_ID());
acct_cr = cr.getAccount(); // PPV Offset
} }
// PPV Offset // PPV Offset
FactLine dr = fact.createLine(null, FactLine dr = fact.createLine(null,
getAccount(Doc.ACCTTYPE_PPVOffset, as), getAccount(Doc.ACCTTYPE_PPVOffset, as),
as.getC_Currency_ID(), isReturnTrx ? difference : difference.negate()); as.getC_Currency_ID(), isReturnTrx ? difference : difference.negate());
MAccount acct_db = null;
if (dr != null) if (dr != null)
{ {
dr.setQty(isReturnTrx ? getQty() : getQty().negate()); dr.setQty(isReturnTrx ? getQty() : getQty().negate());
@ -237,16 +240,14 @@ public class Doc_MatchPO extends Doc
dr.setC_UOM_ID(m_oLine.getC_UOM_ID()); dr.setC_UOM_ID(m_oLine.getC_UOM_ID());
dr.setUser1_ID(m_oLine.getUser1_ID()); dr.setUser1_ID(m_oLine.getUser1_ID());
dr.setUser2_ID(m_oLine.getUser2_ID()); dr.setUser2_ID(m_oLine.getUser2_ID());
acct_db = dr.getAccount(); // PPV
} }
// Avoid usage of clearing accounts // Avoid usage of clearing accounts
// If both accounts Purchase Price Variance and Purchase Price Variance Offset are equal // If both accounts Purchase Price Variance and Purchase Price Variance Offset are equal
// then remove the posting // then remove the posting
MAccount acct_db = dr.getAccount(); // PPV if ((!as.isPostIfClearingEqual()) && acct_db!=null && acct_db.equals(acct_cr) && (!isInterOrg)) {
MAccount acct_cr = cr.getAccount(); // PPV Offset
if ((!as.isPostIfClearingEqual()) && acct_db.equals(acct_cr) && (!isInterOrg)) {
BigDecimal debit = dr.getAmtSourceDr(); BigDecimal debit = dr.getAmtSourceDr();
BigDecimal credit = cr.getAmtSourceCr(); BigDecimal credit = cr.getAmtSourceCr();

View File

@ -165,7 +165,7 @@ public class GridWindowVO implements Serializable
} }
// Ensure ASP exceptions // Ensure ASP exceptions
MRole role = MRole.getDefault(ctx, false); MRole role = MRole.getDefault(ctx, false);
final Boolean windowAccess = role.getWindowAccess(vo.AD_Window_ID); final Boolean windowAccess = vo!=null ? role.getWindowAccess(vo.AD_Window_ID) : null;
if (vo != null && windowAccess == null) if (vo != null && windowAccess == null)
vo = null; // Not found vo = null; // Not found
if (vo != null && windowAccess != null) if (vo != null && windowAccess != null)

View File

@ -170,9 +170,9 @@ public class MAssetAddition extends X_A_Asset_Addition
asset.setA_Asset_Group_ID(product.getA_Asset_Group_ID()); asset.setA_Asset_Group_ID(product.getA_Asset_Group_ID());
MAttributeSetInstance asi = MAttributeSetInstance.create(Env.getCtx(), product, null); MAttributeSetInstance asi = MAttributeSetInstance.create(Env.getCtx(), product, null);
asset.setM_AttributeSetInstance_ID(asi.getM_AttributeSetInstance_ID()); asset.setM_AttributeSetInstance_ID(asi.getM_AttributeSetInstance_ID());
} asset.setName(product.getName().concat(project.getName()));
asset.setName(product.getName().concat(project.getName())); asset.setValue(product.getName().concat(project.getName()));
asset.setValue(product.getName().concat(project.getName())); }
asset.saveEx(); asset.saveEx();
asset.dump(); asset.dump();

View File

@ -1656,7 +1656,7 @@ public class MCost extends X_M_Cost
} }
//-ve current qty will break moving average costing //-ve current qty will break moving average costing
if ((ce.isAveragePO() || ce.isAverageInvoice()) && is_ValueChanged(COLUMNNAME_CurrentQty)) if (ce!=null && (ce.isAveragePO() || ce.isAverageInvoice()) && is_ValueChanged(COLUMNNAME_CurrentQty))
{ {
if (getCurrentQty().signum() < 0) if (getCurrentQty().signum() < 0)
{ {

View File

@ -450,6 +450,8 @@ public class MLookupFactory
{ {
s_log.log(Level.INFO, "No Identifier records found: " + KeyColumn); s_log.log(Level.INFO, "No Identifier records found: " + KeyColumn);
} }
if (list == null)
list = new ArrayList<LookupDisplayColumn>();
list.add(new LookupDisplayColumn(KeyColumn, null, false, DisplayType.ID, 0)); list.add(new LookupDisplayColumn(KeyColumn, null, false, DisplayType.ID, 0));
} }
// set isTranslated // set isTranslated
@ -699,6 +701,8 @@ public class MLookupFactory
{ {
s_log.log(Level.INFO, "No Identifier records found: " + ColumnName); s_log.log(Level.INFO, "No Identifier records found: " + ColumnName);
} }
if (list == null)
list = new ArrayList<LookupDisplayColumn>();
list.add(new LookupDisplayColumn(KeyColumn, null, false, DisplayType.ID, 0)); list.add(new LookupDisplayColumn(KeyColumn, null, false, DisplayType.ID, 0));
} }

View File

@ -458,7 +458,7 @@ public class FinReport extends SvrProcess
if (PostingType != null && PostingType.length() > 0) if (PostingType != null && PostingType.length() > 0)
select.append(" AND PostingType='").append(PostingType).append("'"); select.append(" AND PostingType='").append(PostingType).append("'");
// globalqss - CarlosRuiz // globalqss - CarlosRuiz
if (PostingType.equals(MReportColumn.POSTINGTYPE_Budget)) { if (MReportColumn.POSTINGTYPE_Budget.equals(PostingType)) {
if (m_columns[col].getGL_Budget_ID() > 0) if (m_columns[col].getGL_Budget_ID() > 0)
select.append(" AND GL_Budget_ID=" + m_columns[col].getGL_Budget_ID()); select.append(" AND GL_Budget_ID=" + m_columns[col].getGL_Budget_ID());
} }
@ -977,7 +977,7 @@ public class FinReport extends SvrProcess
if (PostingType != null && PostingType.length() > 0) if (PostingType != null && PostingType.length() > 0)
select.append(" AND fb.PostingType='").append(PostingType).append("'"); select.append(" AND fb.PostingType='").append(PostingType).append("'");
// globalqss - CarlosRuiz // globalqss - CarlosRuiz
if (PostingType.equals(MReportColumn.POSTINGTYPE_Budget)) { if (MReportColumn.POSTINGTYPE_Budget.equals(PostingType)) {
if (m_columns[col].getGL_Budget_ID() > 0) if (m_columns[col].getGL_Budget_ID() > 0)
select.append(" AND GL_Budget_ID=" + m_columns[col].getGL_Budget_ID()); select.append(" AND GL_Budget_ID=" + m_columns[col].getGL_Budget_ID());
} }

View File

@ -163,7 +163,7 @@ implements org.compiere.model.ModelValidator, org.compiere.model.FactsValidator
if (product_id > 0) { if (product_id > 0) {
MProduct prod = MProduct.get(m.getCtx(), product_id); MProduct prod = MProduct.get(m.getCtx(), product_id);
isAsset = (prod != null && prod.get_ID() > 0 && prod.isCreateAsset()); isAsset = (prod != null && prod.get_ID() > 0 && prod.isCreateAsset());
assetGroup_ID = prod.getA_Asset_Group_ID(); assetGroup_ID = prod!=null ? prod.getA_Asset_Group_ID() : 0;
} }
// end modification by @win // end modification by @win

View File

@ -79,7 +79,7 @@ public class PoFiller{
Element e = element.properties.get(qName); Element e = element.properties.get(qName);
String value = e != null ? e.contents.toString() : null; String value = e != null ? e.contents.toString() : null;
if (value.trim().length() == 0) if (value!=null && value.trim().length() == 0)
value = null; value = null;
Timestamp ts = value != null ? Timestamp.valueOf(value) : null; Timestamp ts = value != null ? Timestamp.valueOf(value) : null;
@ -100,7 +100,7 @@ public class PoFiller{
Element e = element.properties.get(qName); Element e = element.properties.get(qName);
String value = e != null ? e.contents.toString() : null; String value = e != null ? e.contents.toString() : null;
if (value.trim().length() == 0) if (value!=null && value.trim().length() == 0)
value = null; value = null;
Integer i = value != null ? new Integer(value) : null; Integer i = value != null ? new Integer(value) : null;
@ -121,7 +121,7 @@ public class PoFiller{
Element e = element.properties.get(qName); Element e = element.properties.get(qName);
String value = e != null ? e.contents.toString() : null; String value = e != null ? e.contents.toString() : null;
if (value.trim().length() == 0) if (value!=null && value.trim().length() == 0)
value = null; value = null;
BigDecimal bd = value != null ? new BigDecimal(value) : null; BigDecimal bd = value != null ? new BigDecimal(value) : null;

View File

@ -519,7 +519,7 @@ public class WAcctViewerData
if (column != null && column.startsWith("Date")) if (column != null && column.startsWith("Date"))
rm.addColumn(new RColumn(ctx, column, DisplayType.Date)); rm.addColumn(new RColumn(ctx, column, DisplayType.Date));
else if (column.startsWith("UserElement")) else if (column!=null && column.startsWith("UserElement"))
{ {
if (column.indexOf('1') != -1) if (column.indexOf('1') != -1)
rm.addColumn(new RColumn(ctx, column, DisplayType.TableDir, null, 0, m_ref1)); rm.addColumn(new RColumn(ctx, column, DisplayType.TableDir, null, 0, m_ref1));

View File

@ -105,11 +105,11 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
WEditor editor = editors.get(gridField); WEditor editor = editors.get(gridField);
if (editor != null) { if (editor != null) {
prepareFieldEditor(gridField, editor); prepareFieldEditor(gridField, editor);
editor.addValueChangeListener(dataBinder);
gridField.removePropertyChangeListener(editor);
gridField.addPropertyChangeListener(editor);
editor.setValue(gridField.getValue());
} }
editor.addValueChangeListener(dataBinder);
gridField.removePropertyChangeListener(editor);
gridField.addPropertyChangeListener(editor);
editor.setValue(gridField.getValue());
return editor; return editor;
} }
@ -305,7 +305,7 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
else else
child = parent; child = parent;
} }
Component component = (Component) div.getAttribute("display.component"); Component component = div!=null ? (Component) div.getAttribute("display.component") : null;
if (updateCellLabel) { if (updateCellLabel) {
if (component instanceof Label) { if (component instanceof Label) {
Label label = (Label)component; Label label = (Label)component;
@ -344,21 +344,29 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
@Override @Override
public void render(Row row, Object[] data, int index) throws Exception { public void render(Row row, Object[] data, int index) throws Exception {
//don't render if not visible //don't render if not visible
if (gridPanel != null && !gridPanel.isVisible()) { int columnCount = 0;
return; GridField[] gridPanelFields = null;
GridField[] gridTabFields = null;
boolean isGridViewCustomized = false;
if (gridPanel != null) {
if (!gridPanel.isVisible()) {
return;
}
else{
gridPanelFields = gridPanel.getFields();
columnCount = gridPanelFields.length;
gridTabFields = gridTab.getFields();
isGridViewCustomized = gridTabFields.length != gridPanelFields.length;
}
} }
if (grid == null) if (grid == null)
grid = (Grid) row.getParent().getParent(); grid = (Grid) row.getParent().getParent();
if (rowListener == null) if (rowListener == null)
rowListener = new RowListener((Grid)row.getParent().getParent()); rowListener = new RowListener((Grid)row.getParent().getParent());
GridField[] gridPanelFields = gridPanel.getFields();
int columnCount = gridPanelFields.length;
GridField[] gridTabFields = gridTab.getFields();
boolean isGridViewCustomized = gridTabFields.length != gridPanelFields.length;
if (!isGridViewCustomized) { if (!isGridViewCustomized) {
for(int i = 0; i < gridTabFields.length; i++) { for(int i = 0; i < gridTabFields.length; i++) {
if (gridPanelFields[i].getAD_Field_ID() != gridTabFields[i].getAD_Field_ID()) { if (gridPanelFields[i].getAD_Field_ID() != gridTabFields[i].getAD_Field_ID()) {

View File

@ -594,7 +594,7 @@ public class WBOMDrop extends ADForm implements EventListener<Event>
if (listitem != null) if (listitem != null)
pp = listitem.toKeyNamePair(); pp = listitem.toKeyNamePair();
m_product = MProduct.get (Env.getCtx(), pp.getKey()); m_product = pp!= null ? MProduct.get (Env.getCtx(), pp.getKey()) : null;
createMainPanel(); createMainPanel();
//sizeIt(); //sizeIt();
} }

View File

@ -1125,7 +1125,7 @@ public class WListbox extends Listbox implements IMiniTable, TableValueChangeLis
if(subtotal == null) if(subtotal == null)
subtotal = new Double(0); subtotal = new Double(0);
if(amt == null ) if(amt == null )
subtotal = new Double(0); amt = new Double(0);
total[col] = subtotal + amt; total[col] = subtotal + amt;
} }

View File

@ -326,7 +326,7 @@ public class RolePanel extends Window implements EventListener<Event>, Deferrabl
} }
// //
if (m_clientKNPairs.length == 1) { if (m_clientKNPairs!=null && m_clientKNPairs.length == 1) {
// don't show client if is just one // don't show client if is just one
lstClient.setSelectedIndex(0); lstClient.setSelectedIndex(0);
lblClient.setVisible(false); lblClient.setVisible(false);

View File

@ -316,7 +316,7 @@ public class ConfigOracle implements IDatabaseConfig
monitor.update(new DBConfigStatus(DBConfigStatus.DATABASE_SERVER, "ErrorDatabaseServer", monitor.update(new DBConfigStatus(DBConfigStatus.DATABASE_SERVER, "ErrorDatabaseServer",
pass, true, error)); pass, true, error));
log.info("OK: Database Server = " + databaseServer); log.info("OK: Database Server = " + databaseServer);
data.setProperty(ConfigurationData.ADEMPIERE_DB_SERVER, databaseServer.getHostName()); data.setProperty(ConfigurationData.ADEMPIERE_DB_SERVER, databaseServer!=null ? databaseServer.getHostName() : null);
//store as lower case for better script level backward compatibility //store as lower case for better script level backward compatibility
data.setProperty(ConfigurationData.ADEMPIERE_DB_TYPE, data.getDatabaseType()); data.setProperty(ConfigurationData.ADEMPIERE_DB_TYPE, data.getDatabaseType());
data.setProperty(ConfigurationData.ADEMPIERE_DB_PATH, data.getDatabaseType().toLowerCase()); data.setProperty(ConfigurationData.ADEMPIERE_DB_PATH, data.getDatabaseType().toLowerCase());

View File

@ -101,7 +101,7 @@ public class ConfigPostgreSQL implements IDatabaseConfig
monitor.update(new DBConfigStatus(DBConfigStatus.DATABASE_SERVER, "ErrorDatabaseServer", monitor.update(new DBConfigStatus(DBConfigStatus.DATABASE_SERVER, "ErrorDatabaseServer",
pass, true, error)); pass, true, error));
log.info("OK: Database Server = " + databaseServer); log.info("OK: Database Server = " + databaseServer);
data.setProperty(ConfigurationData.ADEMPIERE_DB_SERVER, databaseServer.getHostName()); data.setProperty(ConfigurationData.ADEMPIERE_DB_SERVER, databaseServer!=null ? databaseServer.getHostName() : null);
//store as lower case for better script level backward compatibility //store as lower case for better script level backward compatibility
data.setProperty(ConfigurationData.ADEMPIERE_DB_TYPE, data.getDatabaseType()); data.setProperty(ConfigurationData.ADEMPIERE_DB_TYPE, data.getDatabaseType());
data.setProperty(ConfigurationData.ADEMPIERE_DB_PATH, data.getDatabaseType().toLowerCase()); data.setProperty(ConfigurationData.ADEMPIERE_DB_PATH, data.getDatabaseType().toLowerCase());

View File

@ -611,7 +611,7 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
Update.append(" SET "); Update.append(" SET ");
int f = updateFields.length(); int f = updateFields!=null ? updateFields.length() : 0;
int fj = joinFields.length(); int fj = joinFields.length();
String updateField = null; String updateField = null;
String joinField = null; String joinField = null;

View File

@ -85,7 +85,7 @@ public class CreateRecord extends TableFixture {
tableOK = true; tableOK = true;
gpo = table.getPO(0, null); gpo = table.getPO(0, null);
} }
poinfo = POInfo.getPOInfo(ctx, table.getAD_Table_ID()); poinfo = POInfo.getPOInfo(ctx, table!=null ? table.getAD_Table_ID() : 0);
} else if (cell_title.equalsIgnoreCase("*Save*")) { } else if (cell_title.equalsIgnoreCase("*Save*")) {
if (i != rows-1) { if (i != rows-1) {
exception(getCell(i, 1), new Exception("*Save* must be called in last row")); exception(getCell(i, 1), new Exception("*Save* must be called in last row"));

View File

@ -139,7 +139,7 @@ public class Login extends TableFixture {
) )
return null; // already logged with same data return null; // already logged with same data
org.compiere.util.Login login = new org.compiere.util.Login(m_ads.getCtx()); org.compiere.util.Login login = new org.compiere.util.Login(m_ads!=null ? m_ads.getCtx() : null);
KeyNamePair[] roles = login.getRoles(m_user, m_password); KeyNamePair[] roles = login.getRoles(m_user, m_password);
if (roles != null) if (roles != null)
{ {

View File

@ -83,7 +83,7 @@ public class ReadRecord extends TableFixture {
} else { } else {
tableOK = true; tableOK = true;
} }
poinfo = POInfo.getPOInfo(ctx, table.getAD_Table_ID()); poinfo = POInfo.getPOInfo(ctx, table!=null ? table.getAD_Table_ID() : 0);
} else if (cell_title.equalsIgnoreCase("*Where*")) { } else if (cell_title.equalsIgnoreCase("*Where*")) {
if (i != 1) { if (i != 1) {
exception(getCell(i, 1), new Exception("*Where* must be defined in second row")); exception(getCell(i, 1), new Exception("*Where* must be defined in second row"));

View File

@ -174,9 +174,9 @@ public class ADLookup {
ile = ile+1; ile = ile+1;
}*/ }*/
int ile = 0; int ile = 0;
finalSQL = info.getSQLCount(); finalSQL = info!=null ? info.getSQLCount() : "";
PreparedStatement pstmt = DB.prepareStatement(finalSQL, null); PreparedStatement pstmt = DB.prepareStatement(finalSQL, null);
info.setParameters (pstmt, true); if (info!=null) info.setParameters (pstmt, true);
ResultSet rs = pstmt.executeQuery(); ResultSet rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
ile = rs.getInt(1); ile = rs.getInt(1);

View File

@ -1057,7 +1057,8 @@ public class ADServiceImpl implements ADService {
value = "2000/01/01 "+ value; value = "2000/01/01 "+ value;
d = m_cs.dateTimeFormat.parse(value); d = m_cs.dateTimeFormat.parse(value);
} }
ts = new Timestamp(d.getTime()); if (d!=null)
ts = new Timestamp(d.getTime());
} }
catch (Exception e) catch (Exception e)
{ {