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

(fmt) Formatter fails to throw exception for String array

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 5.0
    • tools
    • sparc
    • solaris_2.6

      Formatting api doesn't have any specific conversion for array types.
      But For String array its is displaying 0th element for int array it will throw exception. It should exception for String array also.
      The following code and console will explain the abouve context.
      <code>
      import java.util.*;
      public class Test9 {
          public static void main(String[] arg) {
          int[] intArray = new int[10];
          for(int i=0; i < intArray.length; i++) {
              intArray[i]=i;
          }
          String[] messages = new String[intArray.length];
          for(int i=0; i < intArray.length; i++) {
               messages[i] = Integer.toString(i);
          }
          Formatter formatter = new Formatter(System.out);
          formatter.format("%s Messagess \n ",messages);
          formatter.format("%d",intArray);
          
          }
      }
      </code>
      <console>
      vishalb:/home/vv145429/tiger/src/formating/bugs 71 % javac -source 1.5 Test9.java
      vishalb:/home/vv145429/tiger/src/formating/bugs 72 % java Test9
      0 Messagess
       Exception in thread "main" java.util.IllegalFormatConversionException: d != [I
          at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:3639)
          at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2429)
          at java.util.Formatter$FormatSpecifier.print(Formatter.java:2382)
          at java.util.Formatter.format(Formatter.java:2165)
          at java.util.Formatter.format(Formatter.java:2100)
          at Test9.main(Test9.java:14)
      vishalb:/home/vv145429/tiger/src/formating/bugs 73 %
      </console>

            gafter Neal Gafter (Inactive)
            vvegurusunw Viswadeep Veguru (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: