summaryrefslogtreecommitdiff
path: root/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/SafeVarargsApplicability.java
blob: a479ffd060458b45ee167513b814761c9c8a1772 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.util.List;

<error descr="'@SafeVarargs' not applicable to type">@SafeVarargs</error>
public class SafeVarargsTests {
    //fixed arity
    <error descr="@SafeVarargs is not allowed on methods with fixed arity">@SafeVarargs</error>
    public void testNonVarargs1(){}

    <error descr="@SafeVarargs is not allowed on methods with fixed arity">@SafeVarargs</error>
    public void testNonVarargs2(int <warning descr="Parameter 'i' is never used">i</warning>){}

    <error descr="@SafeVarargs is not allowed on methods with fixed arity">@SafeVarargs</error>
    public <T> void testNonVarargs3(T <warning descr="Parameter 't' is never used">t</warning>){}

    //non static/non final
    <error descr="@SafeVarargs is not allowed on non-final instance methods">@SafeVarargs</error>
    public void testNonVarargs4(int... <warning descr="Parameter 'i' is never used">i</warning>){}

    //reassigned
    @SafeVarargs
    public final <T> void testT(T[] tt, T... t) {
        <warning descr="@SafeVarargs do not suppress potentially unsafe operations">t</warning> = tt;
        System.out.println(t[0]);
    }

    //incorrect types
    @SafeVarargs
    public final void testString(<warning descr="@SafeVarargs is not applicable for reifiable types">String...</warning> <warning descr="Parameter 'str' is never used">str</warning>){
    }

    @SafeVarargs
    public final void testStringArray(<warning descr="@SafeVarargs is not applicable for reifiable types">String[]...</warning> <warning descr="Parameter 'str' is never used">str</warning>){
    }

    @SafeVarargs
    public static void testUnbound(<warning descr="@SafeVarargs is not applicable for reifiable types">List<?>...</warning> <warning descr="Parameter 't' is never used">t</warning>){}


    //correct usages
    @SafeVarargs
    public static <T> void foo(T... <warning descr="Parameter 't' is never used">t</warning>){}
    @SafeVarargs
    public static <T> void foo1(List<T>... <warning descr="Parameter 't' is never used">t</warning>){}
    @SafeVarargs
    public static <T> void foo2(List<? extends T>... <warning descr="Parameter 't' is never used">t</warning>){}

}

abstract class AClass {
    @SafeVarargs
    <T> AClass(T... d){
      System.out.println(d);
    }
}

class ABClass extends AClass {
    @SafeVarargs
    <T> ABClass(T... d){
        super(d);
    }
}