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

Formatter does not throw exception for 0 as argument index

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      The documentation of java.util.Formatter (https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/Formatter.html#dpos) says regarding an explicit argument index:
      > The first argument is referenced by "1$"

      And regarding "Ordinary indexing":
      > Ordinary indexing is used when the format specifier contains neither an argument index nor a '<'

      However when using "0$" as explicit argument index, no exception is thrown but instead it is treated like "Ordinary indexing", i.e. the next sequential index is used.
      Expected would be that either:
      - An exception is thrown (preferred)
      - The documentation is adjusted

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      An exception to be thrown
      ACTUAL -
      Explicit index is treated like "Ordinary indexing"

      ---------- BEGIN SOURCE ----------
      String.format("%0$s %0$s", "a", "b")
      ---------- END SOURCE ----------

            igraves Ian Graves
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: