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

Length cannot be stored as unsigned #2483

Closed
gokaco opened this issue May 12, 2019 · 3 comments
Closed

Length cannot be stored as unsigned #2483

gokaco opened this issue May 12, 2019 · 3 comments
Assignees
Milestone

Comments

@gokaco
Copy link
Member

gokaco commented May 12, 2019

This error has come repeatedly in case studies where length was used as unsigned but due to weakness in signedness checker, we had to suppress the error.
Command-

javac -processor signedness ex.java

Code-

import org.checkerframework.checker.signedness.qual.*;
class ex{
	void foo(String a,byte []b){
		@Unsigned int len = a.length();
		@Unsigned int len2 = b.length;
	}
}

Output-

ex.java:4: error: [assignment.type.incompatible] incompatible types in assignment.
		@Unsigned int len = a.length();
		                            ^
  found   : @Signed int
  required: @Unsigned int
ex.java:5: error: [assignment.type.incompatible] incompatible types in assignment.
		@Unsigned int len2 = b.length;
		                      ^
  found   : @Signed int
  required: @Unsigned int
2 errors
`
@mernst
Copy link
Member

mernst commented May 13, 2019

More generally, @NonNegative int should be treated as @Constant (which will later be renamed to @SignednessEither).

@mernst
Copy link
Member

mernst commented May 16, 2019

The Signedness Checker reads annotations from the Value Checker, such as @IntRange.

If the Value Checker properly handles a.length and s.length(), I would expect the Signedness Checker should too.

So there are two things to verify:

  • The Value Checker handles the length method and field.
  • The Signedness Checker reads the Value Checker annotations.

Note that array.length is (or should be) special-cased by the Value Checker, because there is nowhere to write a JDK annotation.

@mernst mernst added this to the Medium milestone May 16, 2019
@gokaco
Copy link
Member Author

gokaco commented Aug 15, 2019

Fixed through #2614

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

3 participants