Skip to content

ExplicitArrayForVarargs should check if call without parameters is possible #5335

@uhafner

Description

@uhafner

The new ExplicitArrayForVarargs check is too strict: sometimes you need to invoke the vararg method with an array of size 0 in order to select the correct method (in case the vararg method is also overloaded).

Example:

    CommentBuilder() { // some tools like Mockito or Hibernate require a no-arg constructor
        this(new String[0]); 
    }

    protected CommentBuilder(final String... prefixesToRemove) {
        prefixes = Arrays.asList(prefixesToRemove);
    }

For this code the new rule suggests:

Avoid explicit array creation for varargs
    (see https://errorprone.info/bugpattern/ExplicitArrayForVarargs)
  Did you mean 'this();'?

Which obviously is wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions