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

"new array[]" and array.length and @MinLen #199

Open
mernst opened this issue Dec 8, 2017 · 1 comment
Open

"new array[]" and array.length and @MinLen #199

mernst opened this issue Dec 8, 2017 · 1 comment

Comments

@mernst
Copy link
Collaborator

mernst commented Dec 8, 2017

Consider the following code:

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

public class NewArrayLengthOf {

    String @MinLen(1) [] member_array;

    public void recurse_definitions(List<String> new_elements) {
        String[] new_array = new String[member_array.length + new_elements.size()];
        member_array = new_array;
    }
}

It should type-check, but the Index Checker issues this output:

% $ch/bin/javac -g NewArrayLengthOf.java -processor index
NewArrayLengthOf.java:10: error: [assignment.type.incompatible] incompatible types in assignment.
        member_array = new_array;
                       ^
  found   : @UnknownVal String @UnknownVal []
  required: @UnknownVal String @ArrayLenRange(from=1, to=2147483647) []
1 error

This is most likely a Value Checker issue.

@panacekcz
Copy link

panacekcz commented Dec 13, 2017

Caused by possible overflow of the addition. If member_array and new_elements have 232 elements in total, an array of length 0 is created. Sorry, that cannot happen. However, because of the overflow, the value checker loses track of the lower bound.
Related: #182

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

No branches or pull requests

2 participants