LuciferYang commented on pull request #34313:
URL: https://github.com/apache/spark/pull/34313#issuecomment-947283510


   We can use the following case to test it
   
   ```
    import java.util.Locale
       import java.util.Formatter
       val sb = new StringBuffer()
       // Send all output to the Appendable object sb
       val formatter = new Formatter(sb, Locale.US)
   
       // Explicit argument indices may be used to re-order output.
       formatter.format("%4$2s %3$2s %2$2s %1$2s", "a", "b", "c", "d")
       assert(sb.toString == " d  c  b  a")
       sb.delete(0, sb.length())
       assert(sb.toString.isEmpty)
       formatter.format("%4$2s %3$2s %2$2s %0$2s", "a", "b", "c", "d")
       assert(sb.toString == " d  c  b  a")
   ```
   
   This case is similar to the example written in the 
https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html
   
   
![image](https://user-images.githubusercontent.com/1475305/138020290-bd698aad-8988-497b-bb97-c09adf9deace.png)
   
   
   The new case tests both `%4$2s %3$2s %2$2s %1$2s` and `%4$2s %3$2s %2$2s 
%0$2s` and they passed when use Java 8,  although "The first argument is 
referenced by "1$", the second by "2$", etc." is specified in the document,  
but `%0$` is not prohibited, and the result of `%0$` is equivalent to `%1$`.
   
   The result of running the above case using Java 11 is the same as that of 
Java 8.
   
   And Exceptions are thrown only when the above case is run using Java 17
   
   ```
   Illegal format argument index = 0
   java.util.IllegalFormatArgumentIndexException: Illegal format argument index 
= 0
       at 
java.base/java.util.Formatter$FormatSpecifier.index(Formatter.java:2808)
       at 
java.base/java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2879)
       at java.base/java.util.Formatter.parse(Formatter.java:2747)
       at java.base/java.util.Formatter.format(Formatter.java:2671)
       at java.base/java.util.Formatter.format(Formatter.java:2625)
   ```
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to