Skip to content

Update description for inspection 'Unchecked generics array creation for varargs parameter'  #76

Open

Description

@unv-unv

Empty vararg parameter triggers inspection:
java_inspection_unchecked_generics_array_for_empty_parameter

Example code:

public class Test
{
    public abstract static class AbstractValueHelper<Value>
    {
        protected final Class<Value> valueType;
        protected final Value[] allowedValues;

        public AbstractValueHelper(Class<Value> valueType, Value... allowedValues)
        {
            this.valueType = valueType;
            this.allowedValues = allowedValues;
        }
    }

    public static class ValueHelper<Value> extends AbstractValueHelper<Value>
    {
        public ValueHelper(Class<Value> valueType) { super(valueType); }
    }
}

Activity

  1. self-assigned this
    on Jul 6, 2017
  2. VISTALL commented on Jul 6, 2017

    @VISTALL
    Member

    It's valid warning.

    javac will generate constructor call like

    super(valueType, (Value[]) new Object[0]);

    That why, it show this error.

    Thanks

  3. unv-unv commented on Jul 6, 2017

    @unv-unv
    ContributorAuthor

    Indeed, there's a compile-time warning by javac:

    Test.java:10: warning: [unchecked] Possible heap pollution from parameterized vararg type Value
            public AbstractValueHelper(Class<Value> valueType, Value... allowedValues)
                                                    ^
      where Value is a type-variable:
        Value extends Object declared in class AbstractValueHelper
    Temp2.java:20: warning: [unchecked] unchecked generic array creation for varargs parameter of type Value[]
            public ValueHelper(Class<Value> valueType) { super(valueType); }
                                                              ^
      where Value is a type-variable:
        Value extends Object declared in class ValueHelper
    

    Then I request inspection description update (with low priority) :)

  4. reopened this on Jul 6, 2017
  5. changed the title [-]Inspection 'Unchecked generics array creation for varargs parameter' false positive for empty vararg parameter[/-] [+]Update description for inspection 'Unchecked generics array creation for varargs parameter' [/+] on Jul 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions