Can squid:S3878 be fixed to prevent false positive?

Hi all.

I’m on SonarQube 6.7.5 (build 38563).

I observe squid:S3878 comes up in this situation:

foo(new Class<?>[] {});

public void foo(Class<?>... parameterTypes) {

But the suggestion does not work to fix it, because you cannot instantiate new Class<?>().

This rule should check to make sure the object being complained about can actually be instantiated. If not, the rule should not be applied.

hello @ndeepizza,

I am not sure I follow your example, if you want to pass empty array, you don’t need any argument

 void bar() {
    foo();  // will call foo with empty array
  void foo(Class<?>... params) {

Hi Tibor,

I tried that. My use case is actually doing work in Java reflection. And when you omit the parameter like you suggested, the code stops working. It’s using those values to deduce what methods to call, etc.

Can you create some example project to demonstrate the issue you are facing? As far as I know, the fix I suggested should work.

I went and tried your suggestion again, and this time it worked. I must have borked something up the previous time causing issues. Let’s close this out!