I’m confused, when I run the first example, I have an error and I can not even compile the second one.
Is IntStream indeed from java.util.stream? Am I missing something?
That being said, I agree that String.format supports arrays as argument, so
String.format("%d and %d", getArray()); // S2275: not enough arguments. FP
Object[] getArray() {
return new Object[]{1,2};
}
should not raise an issue.
I will probably create a ticket once we figure out what I missed from the initial post.
And for the second one, IntStream does not have toArray() with an argument.
For the record, I already created a ticket (SONARJAVA-3506), since without even considering your examples we already have misbehavior when an array is passed as an argument of format.
Good to know, thanks. I am sorry that I have not verified my example; my actual (proprietary) code had some .map() in the middle of the stream operation and I did not realize that IntStream does not support Stream<Integer> methods. Adding a .mapToObj(Integer::valueOf) before .toArray() fixes the compilation problem (this time I have verified it):