Fixed 30056: Cleanup all warnings in src-wad
authorStefan Hühner <stefan.huehner@openbravo.com>
Sun, 31 May 2015 15:43:59 +0200
changeset 26844 e46899b00411
parent 26843 1474b680f216
child 26845 a9518a8e931b
Fixed 30056: Cleanup all warnings in src-wad

XX
- Remove String or int parameter assignment by copying into local variable.
- in Wad#processSelCol use Vector.toArray function to avoid needing to
replace reference in parameter. Note: .toArray will auto-resize itself
to correct size as param is 0-length array
- Fix 2 possible NPE. As code to treat null as empty value was only
called after .debug triggering NPE as param of log4j.debug will be evaluated
even without log level set to debug.
- Wad#getVectorElementsNotRepeated function had parameter which was new empty
Vector in all its 3 callers. As we do not expect more callers (was is
deprecated) just remove the param completely and create new Vector inside
the function removing param assignment.
- in WadUtility instead of assigning to text-param and immediately returning
that value just return it directly as the rest of that function already did.
- in WadNumber. Confusion between non-static function param name + field
inherited from superclass. As those seem to be very clearly utility
functions which should use the param (and not some inherited field) ->
just make them static to remove that confusion.
- WadValidator gets 'friendlyWarnings' flag on construction but does not
currently use it. However we may want to add it (and keep api stable now)
so just supress that unused warning.
src-wad/src/org/openbravo/wad/Wad.java
src-wad/src/org/openbravo/wad/WadUtility.java
src-wad/src/org/openbravo/wad/controls/WADControl.java
src-wad/src/org/openbravo/wad/controls/WADImage.java
src-wad/src/org/openbravo/wad/controls/WADNumber.java
src-wad/src/org/openbravo/wad/controls/WADSearch.java
src-wad/src/org/openbravo/wad/validation/WADValidator.java
--- a/src-wad/src/org/openbravo/wad/Wad.java	Sun May 31 14:06:56 2015 +0200
+++ b/src-wad/src/org/openbravo/wad/Wad.java	Sun May 31 15:43:59 2015 +0200
@@ -1294,8 +1294,7 @@
       }
       for (int i = 0; i < vecAuxSelCol.size(); i++)
         vecSelCol.addElement(vecAuxSelCol.elementAt(i));
-      selCol = new EditionFieldsData[vecSelCol.size()];
-      vecSelCol.copyInto(selCol);
+      return vecSelCol.toArray(new EditionFieldsData[0]);
     }
     return selCol;
   }
@@ -2379,13 +2378,14 @@
    * Generates the where with the params as java vars, to put it in the java file to be used in all
    * the internal searchs, like gotoFirstRow...
    * 
-   * @param strWhere
+   * @param _strWhere
    *          The tab's where clause
    * @param vecParameters
    *          Vector with the parameters for the where clause.
    * @return String with the new static where clause.
    */
-  private String generateStaticWhere(String strWhere, Vector<Object> vecParameters) {
+  private String generateStaticWhere(String _strWhere, Vector<Object> vecParameters) {
+    String strWhere = _strWhere;
     final StringBuffer result = new StringBuffer();
     if (strWhere == null || strWhere.equals(""))
       return strWhere;
@@ -2434,16 +2434,17 @@
    * @param vecTableParametersTop
    *          Vector with the from clause parameters.
    * @param whereClause
-   * @param orderBy
+   * @param _orderBy
    * @throws ServletException
    * @throws IOException
    */
   private void processTabXSQLSortTab(FieldsData[] parentsFieldsData, File fileDir, String strTab,
       String tabName, String tableName, String windowName, String keyColumnName,
       String strColumnSortOrderId, String strColumnSortYNId, Vector<Object> vecParametersTop,
-      Vector<Object> vecTableParametersTop, String javaPackage, String whereClause, String orderBy)
+      Vector<Object> vecTableParametersTop, String javaPackage, String whereClause, String _orderBy)
       throws ServletException, IOException {
     log4j.debug("Processing Sort Tab xsql: " + strTab + ", " + tabName);
+    String orderBy = _orderBy;
     XmlDocument xmlDocumentXsql;
     final String[] discard = { "", "", "hasOrgKey" };
     if (parentsFieldsData == null || parentsFieldsData.length == 0)
@@ -2488,9 +2489,9 @@
       final Vector<Object> vecTable = new Vector<Object>();
       final Vector<Object> vecWhere = new Vector<Object>();
       final FieldsData[] data = FieldsData.identifierColumns(pool, tableName);
-      log4j.debug("Total Identifiers for " + tableName + ": " + data.length);
       if (data == null)
         strFields = "''";
+      log4j.debug("Total Identifiers for " + tableName + ": " + data.length);
       vecCounters.addElement("0");
       vecCounters.addElement("0");
       for (int i = 0; i < data.length; i++) {
@@ -3620,7 +3621,7 @@
    *          Id of the tab.
    * @param tabName
    *          Name of the tab.
-   * @param keyColumnName
+   * @param _keyColumnName
    *          Name of the tab's key column.
    * @param isreadonly
    *          Boolean that means if is a read only tab or not.
@@ -3638,11 +3639,12 @@
    * @throws IOException
    */
   private void processTabHtmlRelation(FieldsData[] parentsFieldsData, File fileDir, String strTab,
-      String tabName, String keyColumnName, boolean isreadonly, WADControl control,
+      String tabName, String _keyColumnName, boolean isreadonly, WADControl control,
       boolean isTranslated, String adLanguage, String tabNamePresentation, String strTable,
       String accessLevel) throws ServletException, IOException {
     log4j.debug("Procesig relation html" + (isTranslated ? " translated" : "") + ": " + strTab
         + ", " + tabName);
+    String keyColumnName = _keyColumnName;
     final String[] discard = new String[1];
     if (parentsFieldsData.length == 0)
       discard[0] = new String("parent");
@@ -3665,12 +3667,10 @@
           "inp" + Sqlc.TransformaNombreColumna(parentsFieldsData[0].name));
       xmlDocument.setParameter("parentKeyName", parentsFieldsData[0].name);
     }
-    xmlDocument.setParameter("importCSS",
-        getVectorElementsNotRepeated(control.getCSSImport(), new Vector<String>(), 1));
-    xmlDocument.setParameter("importJS",
-        getVectorElementsNotRepeated(control.getImport(), new Vector<String>(), 2));
+    xmlDocument.setParameter("importCSS", getVectorElementsNotRepeated(control.getCSSImport(), 1));
+    xmlDocument.setParameter("importJS", getVectorElementsNotRepeated(control.getImport(), 2));
     final StringBuffer script = new StringBuffer();
-    script.append(getVectorElementsNotRepeated(control.getJSCode(), new Vector<String>(), 0));
+    script.append(getVectorElementsNotRepeated(control.getJSCode(), 0));
     script.append("function validateClient(action, form, value) {\n");
     script.append("  var frm=document.frmMain;\n");
     script.append(control.getValidation()).append("\n");
@@ -3687,16 +3687,12 @@
    * 
    * @param data
    *          The main Vector.
-   * @param addedElements
-   *          Vector with the new values to add.
    * @param type
    *          Indicates the type of import (1=CSS, 2=JS).
    * @return String with the list of imports in html format.
    */
-  private String getVectorElementsNotRepeated(Vector<String[]> data, Vector<String> addedElements,
-      int type) {
-    if (addedElements == null)
-      addedElements = new Vector<String>();
+  private String getVectorElementsNotRepeated(Vector<String[]> data, int type) {
+    Vector<String> addedElements = new Vector<String>();
     if (data == null)
       return "";
     final StringBuffer text = new StringBuffer();
@@ -3866,7 +3862,7 @@
    *          Array of parent fields.
    * @param vecFields
    *          Vector with the select clause.
-   * @param isreadonly
+   * @param _isreadonly
    *          Boolean that indicates if the tab is read only or not.
    * @param isSOTrx
    *          Indicates if the tab is a sales tab or not (Y | N).
@@ -3882,13 +3878,14 @@
   private void processTabHtmlEdition(FieldProvider[] efd, FieldProvider[] efdauxiliar,
       File fileDir, String strTab, String tabName, String keyColumnName,
       String tabNamePresentation, String windowId, FieldsData[] parentsFieldsData,
-      Vector<Object> vecFields, boolean isreadonly, String isSOTrx, String strTable,
+      Vector<Object> vecFields, boolean _isreadonly, String isSOTrx, String strTable,
       double pixelSize, String strLanguage, boolean editable, boolean isSecondaryKey)
       throws ServletException, IOException {
     if (log4j.isDebugEnabled())
       log4j.debug("Procesig edition html" + (strLanguage.equals("") ? "" : " translated") + ": "
           + strTab + ", " + tabName);
 
+    boolean isreadonly = _isreadonly;
     final boolean isReadOnlyDefinedTab = (isreadonly && editable); // isReadOnlyDefinedTab:
     // the
     // tab is
@@ -4533,9 +4530,9 @@
    * @return The copy array of FieldsData objects.
    */
   private FieldsData[] copyarray(FieldsData[] from) {
-    log4j.debug("Starting copyarray: " + from.length);
     if (from == null)
       return null;
+    log4j.debug("Starting copyarray: " + from.length);
     final FieldsData[] to = new FieldsData[from.length];
     for (int i = 0; i < from.length; i++) {
       log4j.debug("For copyarray");
--- a/src-wad/src/org/openbravo/wad/WadUtility.java	Sun May 31 14:06:56 2015 +0200
+++ b/src-wad/src/org/openbravo/wad/WadUtility.java	Sun May 31 15:43:59 2015 +0200
@@ -62,8 +62,7 @@
     else if (reference.equals("16"))
       return "TO_CHAR(" + text + ", '" + sqlDateFormat + " HH24:MM:SS')";
     else
-      text = "TO_CHAR(COALESCE(TO_CHAR(" + text + "), ''))";
-    return text;
+      return "TO_CHAR(COALESCE(TO_CHAR(" + text + "), ''))";
   }
 
   public static String columnIdentifier(ConnectionProvider conn, String tableName,
@@ -575,9 +574,10 @@
     return getComboReloadText(token, vecFields, parentsFieldsData, vecComboReload, prefix, "");
   }
 
-  public static String getComboReloadText(String token, Vector<Object> vecFields,
+  public static String getComboReloadText(String _token, Vector<Object> vecFields,
       FieldsData[] parentsFieldsData, Vector<Object> vecComboReload, String prefix,
       String columnname) {
+    String token = _token;
     StringBuffer strOut = new StringBuffer();
     int i = token.indexOf("@");
     while (i != -1) {
@@ -622,9 +622,10 @@
         + Sqlc.TransformaNombreColumna(token) + "\""));
   }
 
-  public static String getDisplayLogicText(String token, Vector<Object> vecFields,
+  public static String getDisplayLogicText(String _token, Vector<Object> vecFields,
       FieldsData[] parentsFieldsData, Vector<Object> vecAuxiliar, Vector<Object> vecDisplayLogic,
       String windowId, Vector<Object> vecContext, boolean save) {
+    String token = _token;
     StringBuffer strOut = new StringBuffer();
     int i = token.indexOf("@");
     while (i != -1) {
--- a/src-wad/src/org/openbravo/wad/controls/WADControl.java	Sun May 31 14:06:56 2015 +0200
+++ b/src-wad/src/org/openbravo/wad/controls/WADControl.java	Sun May 31 15:43:59 2015 +0200
@@ -154,7 +154,8 @@
     return css;
   }
 
-  protected String replaceHTML(String text) {
+  protected String replaceHTML(String _text) {
+    String text = _text;
     text = text.replace("<HTML>", "");
     text = text.replace("<HEAD>", "");
     text = text.replace("<BODY>", "");
--- a/src-wad/src/org/openbravo/wad/controls/WADImage.java	Sun May 31 14:06:56 2015 +0200
+++ b/src-wad/src/org/openbravo/wad/controls/WADImage.java	Sun May 31 15:43:59 2015 +0200
@@ -148,7 +148,8 @@
     return texto.toString();
   }
 
-  public int addAdditionDefaulSQLFields(Vector<Object> v, FieldsData fieldsDef, int itable) {
+  public int addAdditionDefaulSQLFields(Vector<Object> v, FieldsData fieldsDef, int _itable) {
+    int itable = _itable;
     if (fieldsDef.isdisplayed.equals("Y")) { // Image
       final FieldsData fd = new FieldsData();
       fd.adcolumnid = fieldsDef.adcolumnid + "_" + (itable++);
@@ -179,7 +180,8 @@
   }
 
   public int addAdditionDefaulJavaFields(StringBuffer strDefaultValues, FieldsData fieldsDef,
-      String tabName, int itable) {
+      String tabName, int _itable) {
+    int itable = _itable;
     if (fieldsDef.isdisplayed.equals("Y")) {
       strDefaultValues.append(", " + tabName + "Data.selectDef" + fieldsDef.adcolumnid + "_"
           + (itable++) + "(this, " + fieldsDef.defaultvalue + ")");
--- a/src-wad/src/org/openbravo/wad/controls/WADNumber.java	Sun May 31 14:06:56 2015 +0200
+++ b/src-wad/src/org/openbravo/wad/controls/WADNumber.java	Sun May 31 15:43:59 2015 +0200
@@ -205,32 +205,32 @@
     }
   }
 
-  private boolean isDecimalNumber(String reference) {
+  private static boolean isDecimalNumber(String reference) {
     if (reference == null || reference.equals(""))
       return false;
     return (reference.equals("12") || reference.equals("22"));
   }
 
-  private boolean isGeneralNumber(String reference) {
+  private static boolean isGeneralNumber(String reference) {
     if (reference == null || reference.equals(""))
       return false;
     return reference.equals("800019");
   }
 
-  private boolean isQtyNumber(String reference) {
+  private static boolean isQtyNumber(String reference) {
     if (reference == null || reference.equals(""))
       return false;
     return reference.equals("29");
   }
 
-  private boolean isPriceNumber(String reference) {
+  private static boolean isPriceNumber(String reference) {
     if (reference == null || reference.equals(""))
       return false;
     return reference.equals("800008");
 
   }
 
-  private boolean isIntegerNumber(String reference) {
+  private static boolean isIntegerNumber(String reference) {
     if (reference == null || reference.equals(""))
       return false;
     return reference.equals("11");
--- a/src-wad/src/org/openbravo/wad/controls/WADSearch.java	Sun May 31 14:06:56 2015 +0200
+++ b/src-wad/src/org/openbravo/wad/controls/WADSearch.java	Sun May 31 15:43:59 2015 +0200
@@ -270,7 +270,8 @@
     return true;
   }
 
-  public int addAdditionDefaulSQLFields(Vector<Object> v, FieldsData fieldsDef, int itable) {
+  public int addAdditionDefaulSQLFields(Vector<Object> v, FieldsData fieldsDef, int _itable) {
+    int itable = _itable;
     if (fieldsDef.isdisplayed.equals("Y")) {
       final FieldsData fd = new FieldsData();
       fd.adcolumnid = fieldsDef.adcolumnid + "_" + (itable++);
@@ -393,7 +394,8 @@
   }
 
   public int addAdditionDefaulJavaFields(StringBuffer strDefaultValues, FieldsData fieldsDef,
-      String tabName, int itable) {
+      String tabName, int _itable) {
+    int itable = _itable;
     if (fieldsDef.isdisplayed.equals("Y")) {
 
       HashMap<String, String> tableColumnName = getTableColumnName(fieldsDef);
--- a/src-wad/src/org/openbravo/wad/validation/WADValidator.java	Sun May 31 14:06:56 2015 +0200
+++ b/src-wad/src/org/openbravo/wad/validation/WADValidator.java	Sun May 31 15:43:59 2015 +0200
@@ -31,6 +31,8 @@
   private String modules;
   private ConnectionProvider conn;
   private String checkAll;
+  @SuppressWarnings("unused")
+  // maybe planned some day, so lets keep
   private boolean friendlyWarnings;
 
   /**