Consider the following code:
void main(String[] args) {
System.out.println(java.util.FormatProcessor.FMT.process(StringTemplate.RAW."%8\{args.length}"));
System.out.println(java.util.FormatProcessor.FMT."%8\{args.length}");
}
Instead of %8s, it uses %8 only. However, running the code results in the following output:
%s
Exception in thread "main" java.lang.BootstrapMethodError: bootstrap method initialization exception
at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:188)
at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:316)
at java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:275)
at java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:265)
at Specialized.main(Specialized.java:3)
Caused by: java.lang.IllegalArgumentException: fragments size not equal ptypes size plus one
at java.base/java.lang.invoke.StringConcatFactory.makeConcatWithTemplate(StringConcatFactory.java:1080)
at java.base/java.util.FormatterBuilder.build(FormatterBuilder.java:480)
at java.base/java.util.FormatProcessor.linkage(FormatProcessor.java:204)
at java.base/java.lang.runtime.TemplateRuntime.processStringTemplate(TemplateRuntime.java:229)
at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:167)
... 4 more
The reason is that the behavior of the specialized MethodHandle differds from the behavior of the process method. I'm not sure what the expected behavior should be, but from reading the javadoc, I think both variants are incorrect.