You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ddlutils-dev@db.apache.org by "Thomas Dudziak (JIRA)" <ji...@apache.org> on 2008/06/16 05:41:44 UTC

[jira] Resolved: (DDLUTILS-190) column.setSize needs to be a bit more robust when trying to convert numbers

     [ https://issues.apache.org/jira/browse/DDLUTILS-190?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thomas Dudziak resolved DDLUTILS-190.
-------------------------------------

       Resolution: Fixed
    Fix Version/s: 1.1

The Column.setSize only needs to be slightly more robust wrt. to whitespace. It should not have to be aware of 'special' values such as "null". Instead, I made the contract more explicit in the javadoc and the XML parsing more robust.

> column.setSize needs to be a bit more robust when trying to convert numbers
> ---------------------------------------------------------------------------
>
>                 Key: DDLUTILS-190
>                 URL: https://issues.apache.org/jira/browse/DDLUTILS-190
>             Project: DdlUtils
>          Issue Type: Bug
>          Components: Core (No specific database)
>            Reporter: Joe Fisher
>            Assignee: Thomas Dudziak
>             Fix For: 1.1
>
>
> When the xml file uses the text "null" to describe a null column, the setSize does not handle this case, I wrapped it in number format exception, and null it out. Added log to column.java
> Below is the patch to fix this issue:
> Index: src/java/org/apache/ddlutils/model/Column.java
> ===================================================================
> --- src/java/org/apache/ddlutils/model/Column.java  (revision 608559)
> +++ src/java/org/apache/ddlutils/model/Column.java  (working copy)
> @@ -29,6 +29,9 @@
>  import org.apache.commons.beanutils.ConvertUtils;
>  import org.apache.commons.lang.builder.EqualsBuilder;
>  import org.apache.commons.lang.builder.HashCodeBuilder;
> +import org.apache.commons.logging.Log;
> +import org.apache.commons.logging.LogFactory;
> +
>  import org.apache.ddlutils.util.Jdbc3Utils;
>  /**
> @@ -41,6 +44,8 @@
>      /** Unique ID for serialization purposes. */
>      private static final long serialVersionUID = -6226348998874210093L;
> +    private static final Log _log = LogFactory.getLog(Column.class);
> +
>      /** The name of the column. */
>      private String _name;
>      /** The java name of the column (optional and unused by DdlUtils, for Torque compatibility). */
> @@ -322,16 +327,24 @@
>              int pos = size.indexOf(",");
>              _size  = size;
> -            if (pos < 0)
> +            try
>              {
> +                if (pos < 0)
> +                {
> +                    _scale     = 0;
> +                    _sizeAsInt = new Integer(_size);
> +                }
> +                else
> +                {
> +                    _sizeAsInt = new Integer(size.substring(0, pos));
> +                    _scale     = Integer.parseInt(size.substring(pos + 1));
> +                }
> +            } catch (NumberFormatException ex) {
> +                _log.warn(String.format("Unable to convert %s to a number or number,scale. Setting to null", _size), ex);
> +                _size      = null;
> +                _sizeAsInt = null;
>                  _scale     = 0;
> -                _sizeAsInt = new Integer(_size);
>              }
> -            else
> -            {
> -                _sizeAsInt = new Integer(size.substring(0, pos));
> -                _scale     = Integer.parseInt(size.substring(pos + 1));
> -            }
>          }
>          else
>          {

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.