Uploaded image for project: 'Axis2'
  1. Axis2
  2. AXIS2-5342

Generated code for xsd:totalDigits cause errors

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.6.2
    • 1.6.3, 1.7.0
    • adb, codegen
    • None

    Description

      If you have a element like

      <xsd:simpleType name="abc">
      <xsd:restriction base="xsd:integer">
      <xsd:totalDigits value="5" />
      </xsd:restriction>
      </xsd:simpleType>

      axis generates this as source code

      public void setAbc(java.math.BigInteger param){
      java.lang.String totalDigitsDecimal = org.apache.axis2.databinding.utils.ConverterUtil.convertToStandardDecimalNotation("5").toString();
      if (org.apache.axis2.databinding.utils.ConverterUtil.compare(param, totalDigitsDecimal) > 0)

      { this.localHerkunftsschluessel=param; }

      else

      { throw new java.lang.RuntimeException(); }

      }

      The problem is the toString() of the result from .convertToStandardDecimalNotation("5"). It converts the a BigDecimal into String and this results in "10000.0". Then ConverterUtil.compare() trys to convert this string into a Long. BANG.

      Please change convertToStandardDecimalNotation().toString() into convertToStandardDecimalNotation().toPlainString().

      The same functionality should be evaluated for xsd:int, xsd:float, xsd:decimal ...

      IMHO, this results from a bad implementation of AXIS2-4190. Please add testcases for this.

      Take a look at the following comment and below.

      https://issues.apache.org/jira/browse/AXIS2-4190?focusedCommentId=13285198&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13285198

      Attachments

        Issue Links

          Activity

            toodou chenfeng added a comment -

            java.lang.String totalDigitsDecimal = org.apache.axis2.databinding.utils.ConverterUtil.convertToStandardDecimalNotation("5").toString();
            1.6.3 have not resoled this problem now.
            you could try it again.
            convertToStandardDecimalNotation().toString() into convertToStandardDecimalNotation().toPlainString().
            did not help to this issue.
            results is in "10000.0" yet.
            I think we need a results is 10000.

            but if the number like 13 not the 5 , it is work.results is in "10000000000000"
            i wish it will help you.

            toodou chenfeng added a comment - java.lang.String totalDigitsDecimal = org.apache.axis2.databinding.utils.ConverterUtil.convertToStandardDecimalNotation("5").toString(); 1.6.3 have not resoled this problem now. you could try it again. convertToStandardDecimalNotation().toString() into convertToStandardDecimalNotation().toPlainString(). did not help to this issue. results is in "10000.0" yet. I think we need a results is 10000. but if the number like 13 not the 5 , it is work.results is in "10000000000000" i wish it will help you.
            pramodca Pramod CA added a comment -

            We are using wsdl and xsds from a 3rd party which has totaldigits constraint, removing usage of totaldigits in xsd is cumbersome, could you please let us know when do we get the next version, which has the fix?

            Is there any other way to avoid this issue without modifying the stub or xsd?

            pramodca Pramod CA added a comment - We are using wsdl and xsds from a 3rd party which has totaldigits constraint, removing usage of totaldigits in xsd is cumbersome, could you please let us know when do we get the next version, which has the fix? Is there any other way to avoid this issue without modifying the stub or xsd?
            teyckmans Tom Eyckmans added a comment -

            I've got a similar issue with the convertToStandardDecimalNotation and compare functions of the ConverterUtil class:

            java.lang.String totalDigitsDecimal = org.apache.axis2.databinding.utils.ConverterUtil.convertToStandardDecimalNotation("18").toString();
            if (org.apache.axis2.databinding.utils.ConverterUtil.compare(param, totalDigitsDecimal) > 0){
            this.localEanIdType=param;
            }

            The toString() method results in "1.0E+18" and causes a:

            Caused by: java.lang.NumberFormatException: For input string: "1.0E+18"
            at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
            at java.lang.Long.parseLong(Long.java:441)
            at java.lang.Long.parseLong(Long.java:483)
            at org.apache.axis2.databinding.utils.ConverterUtil.compare(ConverterUtil.java:1277)

            I've changed the code as a workaround to:
            java.lang.String totalDigitsDecimal = "" + org.apache.axis2.databinding.utils.ConverterUtil.convertToStandardDecimalNotation("18").longValue();
            if (org.apache.axis2.databinding.utils.ConverterUtil.compare(param, totalDigitsDecimal) < 0) { ...

            using default formatting here because in ConverterUtil compare Long.parseLong(value) also uses default formatting, changed if check from > to < because convertToStandardDecimalNotation generates the first 19 digit number (you'll run into a problem using this approach when you actually want to use Long.MAX_VALUE) and a smaller (valid) number generates a negative number. valid numbers don't generate a positive compare result.

            teyckmans Tom Eyckmans added a comment - I've got a similar issue with the convertToStandardDecimalNotation and compare functions of the ConverterUtil class: java.lang.String totalDigitsDecimal = org.apache.axis2.databinding.utils.ConverterUtil.convertToStandardDecimalNotation("18").toString(); if (org.apache.axis2.databinding.utils.ConverterUtil.compare(param, totalDigitsDecimal) > 0){ this.localEanIdType=param; } The toString() method results in "1.0E+18" and causes a: Caused by: java.lang.NumberFormatException: For input string: "1.0E+18" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Long.parseLong(Long.java:441) at java.lang.Long.parseLong(Long.java:483) at org.apache.axis2.databinding.utils.ConverterUtil.compare(ConverterUtil.java:1277) I've changed the code as a workaround to: java.lang.String totalDigitsDecimal = "" + org.apache.axis2.databinding.utils.ConverterUtil.convertToStandardDecimalNotation("18").longValue(); if (org.apache.axis2.databinding.utils.ConverterUtil.compare(param, totalDigitsDecimal) < 0) { ... using default formatting here because in ConverterUtil compare Long.parseLong(value) also uses default formatting, changed if check from > to < because convertToStandardDecimalNotation generates the first 19 digit number (you'll run into a problem using this approach when you actually want to use Long.MAX_VALUE) and a smaller (valid) number generates a negative number. valid numbers don't generate a positive compare result.
            autoaim800 Bill Minglei Zhang added a comment - - edited

            The following code was generated using axis2-1.6.2, it's .compare(param, totalDigitsDecimal) > 0, should be <, correct?

                public void setDecimal154(java.math.BigDecimal param) {
            
                    java.lang.String totalDigitsDecimal = org.apache.axis2.databinding.utils.ConverterUtil
                            .convertToStandardDecimalNotation("15").toString();
                    if (org.apache.axis2.databinding.utils.ConverterUtil.compare(param, totalDigitsDecimal) > 0) {
                        this.localDecimal154 = param;
                    } else {
                        throw new java.lang.RuntimeException();
                    }
            
                }
            
            <xs:simpleType name="decimal-15-4">
            	<xs:restriction base="xs:decimal">
            		<xs:fractionDigits value="4" />
            		<xs:totalDigits value="15" />
            	</xs:restriction>
            </xs:simpleType>
            autoaim800 Bill Minglei Zhang added a comment - - edited The following code was generated using axis2-1.6.2, it's .compare(param, totalDigitsDecimal) > 0 , should be < , correct? public void setDecimal154(java.math.BigDecimal param) { java.lang. String totalDigitsDecimal = org.apache.axis2.databinding.utils.ConverterUtil .convertToStandardDecimalNotation( "15" ).toString(); if (org.apache.axis2.databinding.utils.ConverterUtil.compare(param, totalDigitsDecimal) > 0) { this .localDecimal154 = param; } else { throw new java.lang.RuntimeException(); } } <xs:simpleType name= "decimal-15-4" > <xs:restriction base= "xs:decimal" > <xs:fractionDigits value= "4" /> <xs:totalDigits value= "15" /> </xs:restriction> </xs:simpleType>
            axis_skh Soumya K H added a comment -

            I am facing the exact same issue. Can someone please direct on how we can apply the patch 1.7.0 which is supposed to fix this?

            axis_skh Soumya K H added a comment - I am facing the exact same issue. Can someone please direct on how we can apply the patch 1.7.0 which is supposed to fix this?
            sb89 Steven Blake added a comment - - edited

            Is the fix for this to change '>' to '<' ?

            public void setCurr132(java.math.BigDecimal param){
                                        
              java.lang.String totalDigitsDecimal = org.apache.axis2.databinding.utils.ConverterUtil.convertToStandardDecimalNotation("13").toString();
            
              if (org.apache.axis2.databinding.utils.ConverterUtil.compare(param, totalDigitsDecimal) < 0){
                this.localCurr132=param;
              }else {
                throw new java.lang.RuntimeException();
              }                                       
            }
            
            
            sb89 Steven Blake added a comment - - edited Is the fix for this to change '>' to '<' ? public void setCurr132(java.math.BigDecimal param){ java.lang. String totalDigitsDecimal = org.apache.axis2.databinding.utils.ConverterUtil.convertToStandardDecimalNotation( "13" ).toString(); if (org.apache.axis2.databinding.utils.ConverterUtil.compare(param, totalDigitsDecimal) < 0){ this .localCurr132=param; } else { throw new java.lang.RuntimeException(); } }
            khalithbasha khalithbasha added a comment -

            I am facing same issue. Exception in thread "main" java.lang.NumberFormatException: For input string: "1000.0"

            public void setEMPL_RCDTypeDef(int param) {
            java.lang.String totalDigitsDecimal = org.apache.axis2.databinding.utils.ConverterUtil.convertToStandardDecimalNotation(
            "3").toPlainString();

            if (org.apache.axis2.databinding.utils.ConverterUtil.compare(
            param, totalDigitsDecimal) < 0)

            { this.localEMPL_RCDTypeDef = param; }

            else

            { throw new java.lang.RuntimeException( "Input values do not follow defined XSD restrictions"); }

            }

            Version is Axis2 - 1.7.5. Kindly help me on the same.

            khalithbasha khalithbasha added a comment - I am facing same issue. Exception in thread "main" java.lang.NumberFormatException: For input string: "1000.0" public void setEMPL_RCDTypeDef(int param) { java.lang.String totalDigitsDecimal = org.apache.axis2.databinding.utils.ConverterUtil.convertToStandardDecimalNotation( "3").toPlainString(); if (org.apache.axis2.databinding.utils.ConverterUtil.compare( param, totalDigitsDecimal) < 0) { this.localEMPL_RCDTypeDef = param; } else { throw new java.lang.RuntimeException( "Input values do not follow defined XSD restrictions"); } } Version is Axis2 - 1.7.5. Kindly help me on the same.
            khalithbasha khalithbasha added a comment -

            Exception in thread "main" java.lang.NumberFormatException: For input string: "1000.0"

            public void setEMPL_RCDTypeDef(int param) {
            java.lang.String totalDigitsDecimal = org.apache.axis2.databinding.utils.ConverterUtil.convertToStandardDecimalNotation(
            "3").toPlainString();

            if (org.apache.axis2.databinding.utils.ConverterUtil.compare(
            param, totalDigitsDecimal) < 0)

            { this.localEMPL_RCDTypeDef = param; }

            else

            { throw new java.lang.RuntimeException( "Input values do not follow defined XSD restrictions"); }

            }

            khalithbasha khalithbasha added a comment - Exception in thread "main" java.lang.NumberFormatException: For input string: "1000.0" public void setEMPL_RCDTypeDef(int param) { java.lang.String totalDigitsDecimal = org.apache.axis2.databinding.utils.ConverterUtil.convertToStandardDecimalNotation( "3").toPlainString(); if (org.apache.axis2.databinding.utils.ConverterUtil.compare( param, totalDigitsDecimal) < 0) { this.localEMPL_RCDTypeDef = param; } else { throw new java.lang.RuntimeException( "Input values do not follow defined XSD restrictions"); } }

            People

              Unassigned Unassigned
              azgard Conny Kreyßel
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: