-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Java: Consider AssignOps in ArithExpr #14254
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
Conversation
To consider while we're here: move out of Overflow.qll, probably to plain old Expr.qll? It seems like a generally useful category of expressions not particularly bound to the overflow queries. |
I considered it, but the Happy to do it as its own thing in a different PR if you think it makes sense though. |
I gave this a try in a query I'm working on that depends on the arithmetic assign operations and everything worked great. Looks good to me! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Isn't this change potentially breaking this code? codeql/java/ql/lib/semmle/code/java/Conversions.qll Lines 126 to 133 in 3e1164f
If we consider "Java Language Specification, Section 5.4." to actually refer to https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.6 then it does not list assignment arithmetic operators. |
I'm no expert, but a few ideas: What would The Java Language Specification is ambiguous in Section 5.4, but in Section 15.26.2 (Compound Assignment Operators) it states:
That makes it seem as though a compound arithmetic assignment operator (e.g. Testing with both javac 1.8.0_382 and javac 21 (21.0.0.35.1) (wrapped with Maven 3.8.4 via
This program fails to compile with the error "incompatible types: possible lossy conversion from float to int":
It looks as though |
Note that the compound assignment operator description says that Conversions-wise this means that There's also the potentially surprising situation of |
ArithExpr
was considering unary and binary operators, but not compound operators, which are equally relevant for arithmetic-related questions. This PR addsAssignOp
s to the definition ofArithExpr
to address that.