lovubuntu / checker-framework

Automatically exported from code.google.com/p/checker-framework
0 stars 0 forks source link

Can't infer type argument on Arrays.copyOf #296

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Not sure if this is possible, but I'd like to not have to specify the type 
argument to Arrays.copyOf:

    import java.util.Arrays;

    /*>>> import checkers.nullness.quals.Nullable; */
    /*>>> import checkers.nullness.quals.NonNull; */

    class ArrayCopy
    {
        public static <T> void f1(T[] a)
        {
            /*@Nullable*/T[] r = Arrays.copyOf(a, a.length + 1);  // <-- error
        }

        // Workaround: explicit type argument
        public static <T> void f2(T[] a)
        {
            /*@Nullable*/T[] r = Arrays.</*@NonNull*/T>copyOf(a, a.length + 1);
        }
    }

# java -jar binary/checkers.jar -processor checkers.nullness.NullnessChecker 
ArrayCopy.java
ArrayCopy.java:10: error: incompatible types in type argument.
        /*@Nullable*/T[] r = Arrays.copyOf(a, a.length + 1);  // <-- error
                                          ^
  found   : @Nullable T extends @Initialized @Nullable Object
  required: @Initialized @NonNull Object
1 error

Original issue reported on code.google.com by kan...@cakoose.com on 19 Dec 2013 at 1:38

GoogleCodeExporter commented 9 years ago
Checker Framework 1.7.1 on Java 1.7.0_25 on Mac OS X 10.8.5.

Original comment by kan...@cakoose.com on 19 Dec 2013 at 1:39

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 23c56eb087d6.

Original comment by wdi...@gmail.com on 22 Dec 2013 at 7:27

GoogleCodeExporter commented 9 years ago
I think the annotations for j.u.Arrays in the annotated JDK were incorrect.
I adapted them and added a test case in tests/nullness/Issue296.java.

As a side note, the "-AinvariantArrays" option reveals a different issue with 
method type argument inference, which we'll solve separately.

Original comment by wdi...@gmail.com on 22 Dec 2013 at 7:35

GoogleCodeExporter commented 9 years ago

Original comment by Jonathan...@gmail.com on 6 Jan 2014 at 6:53