Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-5522

CommonFns.formatNumber() doesn't handle null as javadoc mentions

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 10.0.0
    • 9.6.4
    • None
    • Security Level: Jimmy
    • None

      Steps to Reproduce

      <?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
      <zk>
          <label value="${c:formatNumber(null, '$ ###,###,###.00')}" />
      </zk>
      

      Current Result

      java.lang.IllegalArgumentException: Cannot format given Object as a Number
      java.base/java.text.DecimalFormat.format(DecimalFormat.java:518)
      java.base/java.text.Format.format(Format.java:158)
      org.zkoss.xel.fn.CommonFns.formatNumber(CommonFns.java:491)
      org.zkoss.xel.fn.CommonFns.formatNumber(CommonFns.java:429)

      Expected Result

      empty string.

      Debug Information

      • its javadoc mentioned:

        ... If null, an empty string is returned.

      • Since it's called on a zul, it's better to return an empty string instead of throwing a runtime exception. An EL expression also evaluate a null as an empty string, no exception.

      Workaround

      null check

            jamson jamson
            hawk hawk
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: