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

3 comments


>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

0


>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.


Does this mean that it isn't fixable? Perhaps I should re-look at how I am synchronizing this particular variable anyway...

Mike

0


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

0

Please sign in to leave a comment.