Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arrays.copyOf should propagate length information from argument to return value #3224

Closed
mernst opened this issue Apr 2, 2020 · 0 comments · Fixed by #3524
Closed

Arrays.copyOf should propagate length information from argument to return value #3224

mernst opened this issue Apr 2, 2020 · 0 comments · Fixed by #3524

Comments

@mernst
Copy link
Member

mernst commented Apr 2, 2020

Consider this source code.

import java.util.Arrays;
import org.checkerframework.common.value.qual.MinLen;

public class ArraysCopyOfLength {

  public static void m1(String @MinLen(1) [] args) {
    String @MinLen(1) [] args2 = Arrays.copyOf(args, args.length);
  }

  public static void m2(String @MinLen(1) ... args) {
    String @MinLen(1) [] args2 = Arrays.copyOf(args, args.length);
  }
}

The Index Checker issues these warnings:

ArraysCopyOfLength.java:7: error: [assignment.type.incompatible] incompatible types in assignment.
    String @MinLen(1) [] args2 = Arrays.copyOf(args, args.length);
                                              ^
  found   : @UnknownVal String @UnknownVal []
  required: @UnknownVal String @ArrayLenRange(from=1, to=2147483647) []
ArraysCopyOfLength.java:11: error: [assignment.type.incompatible] incompatible types in assignment.
    String @MinLen(1) [] args2 = Arrays.copyOf(args, args.length);
                                              ^
  found   : @UnknownVal String @UnknownVal []
  required: @UnknownVal String @ArrayLenRange(from=1, to=2147483647) []
2 errors

However, these are false positive warnings, because the result of these calls to Arrays.copyOf should have all the same properties as its argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant