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

(fmt) Formatter fails to format "%.1g" with 0 as argument

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 7u21
    • core-libs
    • x86_64
    • linux

      FULL PRODUCT VERSION :
      java version "1.7.0_21"
      OpenJDK Runtime Environment (IcedTea 2.3.9) (7u21-2.3.9-5)
      OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux 3.12-1-amd64 #1 SMP Debian 3.12.9-1 (2014-02-01) x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      Formatter throws an java.lang.ArrayIndexOutOfBoundsException when the format string is "%.1g" and the value is 0.
      It is ok with a non-null value.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute the attached code


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
      at java.lang.System.arraycopy(Native Method)
      at java.util.Formatter$FormatSpecifier.addZeros(Formatter.java:3401)
      at java.util.Formatter$FormatSpecifier.print(Formatter.java:3295)
      at java.util.Formatter$FormatSpecifier.print(Formatter.java:3190)
      at java.util.Formatter$FormatSpecifier.printFloat(Formatter.java:2757)
      at java.util.Formatter$FormatSpecifier.print(Formatter.java:2708)
      at java.util.Formatter.format(Formatter.java:2488)
      at java.util.Formatter.format(Formatter.java:2423)
      at test.main(test.java:7)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.Formatter;

      public class test {

          public static void main(String[] args) {
      Formatter fmt = new Formatter();
      fmt.format("%.1g", 0.);

      System.out.println(fmt.toString());
          }
      }
      ---------- END SOURCE ----------

            dmeetry Dmeetry Degrave (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: