Inspection Gagets problem
Using the "Show fields accessed from both synchronous and unsynchronous contexts" option, I have a case where I can't get a field to not be tagged.
I am guessing the problem is that the field is passed into methods in an unsynchronized context, but then are synchronized within the method.
Would that not be sufficient, or is there a subtle coding problem?
Also, I assume that synchronization isn't required in the constructor?
Thanks,
Mike
请先登录再写评论。
>I am guessing the problem is that the field is passed into >methods in an unsynchronized context, but then are >synchronized within the method.
Bingo. The call in this case counts as an unsynchronized access of the variable. If you've got another synchronized access elsewhere, you'll trigger a warning.
>Also, I assume that synchronization isn't required in the >constructor?
Correct. Accesses in constructors and initializers don't count for purposes of this inspection. This causes the inspection to miss a few legitimate issues, but the payoff is a lot fewer "false positives".
--Dave Griffith
Does this mean that it isn't fixable? Perhaps I should re-look at how I am synchronizing this particular variable anyway...
Mike
This inspection can, by it's nature, issue errors on correct code. Since a fully correct solution to this issue is almost certainly NP-complete to calculate, this is probably as good as can be accomplished. If you want to call that unfixable, so be it.
--Dave Griffith