Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8199672

ClassCastException is thrown by java.util.Formatter when an NumberFormatProvider SPI is used.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 11
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b07
    • CPU:
      generic
    • Verification:
      Verified

      Description

      An Exception is thrown by Formatter.format method when ICU4j locale spi is used

      Exception in thread "main" java.lang.ClassCastException: com.ibm.icu.impl.jdkadapter.NumberFormatICU cannot be cast to java.base/java.text.DecimalFormat
      at java.base/java.util.Formatter$FormatSpecifier.localizedMagnitude(Formatter.java:4481)
      at java.base/java.util.Formatter$FormatSpecifier.print(Formatter.java:3248)
      at java.base/java.util.Formatter$FormatSpecifier.print(Formatter.java:3233)
      at java.base/java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2933)
      at java.base/java.util.Formatter$FormatSpecifier.print(Formatter.java:2893)
      at java.base/java.util.Formatter.format(Formatter.java:2674)
      at java.base/java.util.Formatter.format(Formatter.java:2610)


      public class FormatterTest {

          public static void main(String[] args) {
              Locale locale = new Locale("hi", "IN");
              StringBuilder sb = new StringBuilder();
              Formatter formatter = new Formatter(sb, locale);
              formatter.format("%,d", 100000);
          }
      }

      Ouput: A ClassCastException is thrown


      Steps to Reproduce

      1. Download icu libraries and put them in project classpath
      http://download.icu-project.org/files/icu4j/59.1/icu4j-59_1.jar
      http://download.icu-project.org/files/icu4j/59.1/icu4j-localespi-59_1.jar

      2) Run above code snippet with VM argument
      -Djava.locale.providers=SPI,COMPAT

        Attachments

          Activity

            People

            • Assignee:
              nishjain Nishit Jain
              Reporter:
              nishjain Nishit Jain
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: