Skip to content

RemoveToStringCallsFromArrayInstances should not use Arrays.toString on String/PrintStream/PrintWriter.format methods #230

@philippe-granet

Description

@philippe-granet

The following code:

    Object[] strings = new Object[]{"foo", "bar"};
    System.out.println(String.format("%s %s", strings));

display foo bar.
But RemoveToStringCallsFromArrayInstances recipe generate this code::

    Object[] strings = new Object[]{"foo", "bar"};
    System.out.println(String.format("%s %s", Arrays.toString(strings)));

that fail with this error:

Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier '%s'
at java.base/java.util.Formatter.format(Formatter.java:2780)
at java.base/java.util.Formatter.format(Formatter.java:2717)
	at java.base/java.lang.String.format(String.java:4150)
	at HelloWorld.main(HelloWorld.java:8)

I think RemoveToStringCallsFromArrayInstances recipe should not use Arrays.toString on String/PrintStream/PrintWriter format methods.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions