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);
if (whereString != null) {
log.fine(whereString.toString());
query.addRestriction(whereString.toString());
}
final boolean ok = openWindow(windowId, query);
if (!ok) {
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,
m_pc.getAccount(ProductCost.ACCTTYPE_P_PPV, as),
as.getC_Currency_ID(), isReturnTrx ? difference.negate() : difference);
MAccount acct_cr = null;
if (cr != null)
{
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.setUser1_ID(m_oLine.getUser1_ID());
cr.setUser2_ID(m_oLine.getUser2_ID());
acct_cr = cr.getAccount(); // PPV Offset
}
// PPV Offset
FactLine dr = fact.createLine(null,
getAccount(Doc.ACCTTYPE_PPVOffset, as),
as.getC_Currency_ID(), isReturnTrx ? difference : difference.negate());
MAccount acct_db = null;
if (dr != null)
{
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.setUser1_ID(m_oLine.getUser1_ID());
dr.setUser2_ID(m_oLine.getUser2_ID());
acct_db = dr.getAccount(); // PPV
}
// Avoid usage of clearing accounts
// If both accounts Purchase Price Variance and Purchase Price Variance Offset are equal
// then remove the posting
MAccount acct_db = dr.getAccount(); // PPV
MAccount acct_cr = cr.getAccount(); // PPV Offset
if ((!as.isPostIfClearingEqual()) && acct_db.equals(acct_cr) && (!isInterOrg)) {
if ((!as.isPostIfClearingEqual()) && acct_db!=null && acct_db.equals(acct_cr) && (!isInterOrg)) {
BigDecimal debit = dr.getAmtSourceDr();
BigDecimal credit = cr.getAmtSourceCr();

View File

@ -165,7 +165,7 @@ public class GridWindowVO implements Serializable
}
// Ensure ASP exceptions
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)
vo = null; // Not found
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());
MAttributeSetInstance asi = MAttributeSetInstance.create(Env.getCtx(), product, null);
asset.setM_AttributeSetInstance_ID(asi.getM_AttributeSetInstance_ID());
}
asset.setName(product.getName().concat(project.getName()));
asset.setValue(product.getName().concat(project.getName()));
}
asset.saveEx();
asset.dump();

View File

@ -1656,7 +1656,7 @@ public class MCost extends X_M_Cost
}
//-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)
{

View File

@ -450,6 +450,8 @@ public class MLookupFactory
{
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));
}
// set isTranslated
@ -699,6 +701,8 @@ public class MLookupFactory
{
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));
}

View File

@ -458,7 +458,7 @@ public class FinReport extends SvrProcess
if (PostingType != null && PostingType.length() > 0)
select.append(" AND PostingType='").append(PostingType).append("'");
// globalqss - CarlosRuiz
if (PostingType.equals(MReportColumn.POSTINGTYPE_Budget)) {
if (MReportColumn.POSTINGTYPE_Budget.equals(PostingType)) {
if (m_columns[col].getGL_Budget_ID() > 0)
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)
select.append(" AND fb.PostingType='").append(PostingType).append("'");
// globalqss - CarlosRuiz
if (PostingType.equals(MReportColumn.POSTINGTYPE_Budget)) {
if (MReportColumn.POSTINGTYPE_Budget.equals(PostingType)) {
if (m_columns[col].getGL_Budget_ID() > 0)
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) {
MProduct prod = MProduct.get(m.getCtx(), product_id);
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

View File

@ -79,7 +79,7 @@ public class PoFiller{
Element e = element.properties.get(qName);
String value = e != null ? e.contents.toString() : null;
if (value.trim().length() == 0)
if (value!=null && value.trim().length() == 0)
value = null;
Timestamp ts = value != null ? Timestamp.valueOf(value) : null;
@ -100,7 +100,7 @@ public class PoFiller{
Element e = element.properties.get(qName);
String value = e != null ? e.contents.toString() : null;
if (value.trim().length() == 0)
if (value!=null && value.trim().length() == 0)
value = null;
Integer i = value != null ? new Integer(value) : null;
@ -121,7 +121,7 @@ public class PoFiller{
Element e = element.properties.get(qName);
String value = e != null ? e.contents.toString() : null;
if (value.trim().length() == 0)
if (value!=null && value.trim().length() == 0)
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"))
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)
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);
if (editor != null) {
prepareFieldEditor(gridField, editor);
}
editor.addValueChangeListener(dataBinder);
gridField.removePropertyChangeListener(editor);
gridField.addPropertyChangeListener(editor);
editor.setValue(gridField.getValue());
}
return editor;
}
@ -305,7 +305,7 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
else
child = parent;
}
Component component = (Component) div.getAttribute("display.component");
Component component = div!=null ? (Component) div.getAttribute("display.component") : null;
if (updateCellLabel) {
if (component instanceof Label) {
Label label = (Label)component;
@ -344,9 +344,22 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
@Override
public void render(Row row, Object[] data, int index) throws Exception {
//don't render if not visible
if (gridPanel != null && !gridPanel.isVisible()) {
int columnCount = 0;
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)
grid = (Grid) row.getParent().getParent();
@ -354,11 +367,6 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
if (rowListener == null)
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) {
for(int i = 0; i < gridTabFields.length; i++) {
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)
pp = listitem.toKeyNamePair();
m_product = MProduct.get (Env.getCtx(), pp.getKey());
m_product = pp!= null ? MProduct.get (Env.getCtx(), pp.getKey()) : null;
createMainPanel();
//sizeIt();
}

View File

@ -1125,7 +1125,7 @@ public class WListbox extends Listbox implements IMiniTable, TableValueChangeLis
if(subtotal == null)
subtotal = new Double(0);
if(amt == null )
subtotal = new Double(0);
amt = new Double(0);
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
lstClient.setSelectedIndex(0);
lblClient.setVisible(false);

View File

@ -316,7 +316,7 @@ public class ConfigOracle implements IDatabaseConfig
monitor.update(new DBConfigStatus(DBConfigStatus.DATABASE_SERVER, "ErrorDatabaseServer",
pass, true, error));
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
data.setProperty(ConfigurationData.ADEMPIERE_DB_TYPE, data.getDatabaseType());
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",
pass, true, error));
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
data.setProperty(ConfigurationData.ADEMPIERE_DB_TYPE, data.getDatabaseType());
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 ");
int f = updateFields.length();
int f = updateFields!=null ? updateFields.length() : 0;
int fj = joinFields.length();
String updateField = null;
String joinField = null;

View File

@ -85,7 +85,7 @@ public class CreateRecord extends TableFixture {
tableOK = true;
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*")) {
if (i != rows-1) {
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
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);
if (roles != null)
{

View File

@ -83,7 +83,7 @@ public class ReadRecord extends TableFixture {
} else {
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*")) {
if (i != 1) {
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;
}*/
int ile = 0;
finalSQL = info.getSQLCount();
finalSQL = info!=null ? info.getSQLCount() : "";
PreparedStatement pstmt = DB.prepareStatement(finalSQL, null);
info.setParameters (pstmt, true);
if (info!=null) info.setParameters (pstmt, true);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
ile = rs.getInt(1);

View File

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