Menu

#6 Spurious antic warnings about Java assertions involving ==

open
nobody
None
5
2004-11-04
2004-11-04
No

antic version 1.11.1 executed with the -java flag on the following
code:

public class Demo
{
public void falsePossibleMissEqWarning(int i)
{
assert i == 3 : "Bother";
}
}

warns "Possible miss of '='". I'm not quite sure what that error
message is intended to mean, but it seems to suggest that I really
meant

assert i = 3 : "Bother";

If I amend the code to a single '=' then antic stops giving warnings,
but javac starts giving errors because i = 3 is an integer
expression rather than a boolean one.

It would seem to make more sense to warn about assertions with
single '=', on the grounds that asserting an expression with side-
effects can cause subtle bugs.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB