Details
-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
6
-
generic
-
generic
Description
From email:
Here's another warning the compiler could give. For the
second time in a week, I've seen code like:
public Random() { this(++seedUniquifier ....); }
private static volatile long seedUniquifier = 8682522807148012L;
where it looks like people think that declaring seedUniquifier
to be volatile means that ++seedUniquifier will work like an
atomic operation. I know it doesn't, and you know it doesn't,
but "people" seem to think it does, hence the need for the
warning. You might get a lot of false positives, though, like
this one in java.util.Random, where the ++ doesn't *have* to
be atomic.
Here's another warning the compiler could give. For the
second time in a week, I've seen code like:
public Random() { this(++seedUniquifier ....); }
private static volatile long seedUniquifier = 8682522807148012L;
where it looks like people think that declaring seedUniquifier
to be volatile means that ++seedUniquifier will work like an
atomic operation. I know it doesn't, and you know it doesn't,
but "people" seem to think it does, hence the need for the
warning. You might get a lot of false positives, though, like
this one in java.util.Random, where the ++ doesn't *have* to
be atomic.