How to make string.format complain at compile time

The compiler has access to the format string AND the required types and parameters. Therefore, I suppose there is some way to specify missing parameters for varargs ... even if it were only for a subset of cases. Is there somewhere for an eclipse or other ide to indicate that the passed varargs can cause a run-time problem?

+8
java eclipse string.format
source share
2 answers

It seems that FindBugs might solve your problem. There are some categories of warnings related to format strings.

+10
source share

The Java compiler does not have built-in semantic knowledge about StringFormat parameters, so it cannot check them at compile time. For everything he knows, StringFormat is another class, and String.format is another method, and this format string is another string, like any other.

But yes, I feel your pain, having faced the same problems in the last couple of days. What they were supposed to do was to make the number of parameters “less cautious” and simply leave the end marks of% s unchanged.

+1
source share

Source: https://habr.com/ru/post/651183/


All Articles