MINA SSHD
  1. MINA SSHD
  2. SSHD-104

FormatFlagsConversionMismatchException when using IBM JVM. Format String is invalid.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 0.5.0, 0.6.0
    • Fix Version/s: 0.6.0
    • Labels:
      None
    • Environment:
      IBM J9 VM (build 2.4, JRE 1.6.0 IBM J9 2.4 Linux x86-32 jvmxi3260sr8ifx-20100609_59383 (JIT enabled, AOT enabled)
      2.6.35-24-generic #42-Ubuntu SMP (Ubuntu 10.10)

      Description

      The following exception is thrown when using SFTP client FileZilla and Mina is running on the IBM JVM:
      java.util.FormatFlagsConversionMismatchException: Mismatched Convertor =s, Flags= #
      at java.util.Formatter$Transformer.transformFromString(Formatter.java:1020)
      at java.util.Formatter$Transformer.transform(Formatter.java:861)
      at java.util.Formatter.format(Formatter.java:565)
      at java.util.Formatter.format(Formatter.java:509)
      at java.lang.String.format(String.java:1960)
      at org.apache.sshd.server.sftp.SftpSubsystem.getLongName(SftpSubsystem.java:843)
      at org.apache.sshd.server.sftp.SftpSubsystem.sendPath(SftpSubsystem.java:806)
      at org.apache.sshd.server.sftp.SftpSubsystem.process(SftpSubsystem.java:719)
      at org.apache.sshd.server.sftp.SftpSubsystem.run(SftpSubsystem.java:331)
      at java.lang.Thread.run(Thread.java:736)

      Latest source shows the problem line:
      847 long length = f.getSize();
      848 String lengthString = String.format("%1$#8s", length);

      Simple test code also reproduces the problem:
      public static void main(String [] args)

      { long length = 12312342; String lengthString = String.format("%1$#8s", length); System.out.println(lengthString); }

      If I understand the Formatter class documentation, I'm surprised the format call works at all on the Sun JVM. It says the # flag is only applicable for Integral types with o, x, and X conversions only. Further down in the documentation for 's' conversion, it says

      "If the '#' flag is given and the argument is not a Formattable , then a FormatFlagsConversionMismatchException will be thrown."

      Assuming the long above is autoboxed to Long, Long does not implement Formattable.

      I believe a different method should be used for converting this long to string. I'm not sure of the original intent, but maybe the the 'd' conversion was intended rather than the 's' conversion to output the long in base 10, but then I don't understand the use of #.

        Activity

        Hide
        Kevin Bulebush added a comment - - edited

        I believe the right fix is to remove the # flag from the format string. My patch, built against tag sshd-0.5.0 is:

            1. Eclipse Workspace Patch 1.0
              #P sshd-core
              Index: src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java
              ===================================================================
            • src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java (revision 1073841)
              +++ src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java (working copy)
              @@ -840,7 +840,7 @@
              }

        long length = f.getSize();

        • String lengthString = String.format("%1$#8s", length);
          + String lengthString = String.format("%1$8s", length);

        StringBuilder sb = new StringBuilder();
        sb.append((f.isDirectory() ? "d" : "-"));

        Patch against trunk:

            1. Eclipse Workspace Patch 1.0
              #P sshd-core
              Index: src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java
              ===================================================================
            • src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java (revision 1073848)
              +++ src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java (working copy)
              @@ -845,7 +845,7 @@
              }

        long length = f.getSize();

        • String lengthString = String.format("%1$#8s", length);
          + String lengthString = String.format("%1$8s", length);

        StringBuilder sb = new StringBuilder();
        sb.append((f.isDirectory() ? "d" : "-"));

        Show
        Kevin Bulebush added a comment - - edited I believe the right fix is to remove the # flag from the format string. My patch, built against tag sshd-0.5.0 is: Eclipse Workspace Patch 1.0 #P sshd-core Index: src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java =================================================================== src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java (revision 1073841) +++ src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java (working copy) @@ -840,7 +840,7 @@ } long length = f.getSize(); String lengthString = String.format("%1$#8s", length); + String lengthString = String.format("%1$8s", length); StringBuilder sb = new StringBuilder(); sb.append((f.isDirectory() ? "d" : "-")); Patch against trunk: Eclipse Workspace Patch 1.0 #P sshd-core Index: src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java =================================================================== src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java (revision 1073848) +++ src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java (working copy) @@ -845,7 +845,7 @@ } long length = f.getSize(); String lengthString = String.format("%1$#8s", length); + String lengthString = String.format("%1$8s", length); StringBuilder sb = new StringBuilder(); sb.append((f.isDirectory() ? "d" : "-"));

          People

          • Assignee:
            Unassigned
            Reporter:
            Kevin Bulebush
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 1h
              1h
              Remaining:
              Remaining Estimate - 1h
              1h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development