Overzealous "inconsistent synchronization" detection

I'm getting the warning "the field is sometimes used inside synchronized block and sometimes used without synchronization."   However, in this case, the flagged field is a constant, so the warning is inappropriate. 

(note:  I'm using ReSharper Ultimate, but that option wasn't available in the Topic dropdown below,  so I picked ReSharper Community)

0
4 comments

Hello!

 

Thank you for the feedback.

Could you please provide some code sample that illustrates the issue?

Thanks in advance!

0
Avatar
Permanently deleted user

I know this is an old thread, but I came accross the same issue, example code to reproduce:

 

    class Program
    {
        private const int Number = 10;

        private static readonly object Lock = new object();

        static void Main(string[] args)
        {
            lock (Lock)
            {
                var x = DateTime.Now.AddMinutes(Number);
            }

            var y = DateTime.Now.AddMinutes(Number);
        }
    }

0

Hello Jfranken!

 

Thank you for the feedback.

Here's correspondent issue reported - https://youtrack.jetbrains.com/issue/RSRP-471666.

Please feel free to comment or vote for it.

Thank you.

0
Avatar
Permanently deleted user

thanks JFranken, for following up with an example.   I got busy with other things and totally forgot about this.

Of course, I don't think JetBrains really needed an example from us.  The description I provided SHOULD have been enough for any entry-level engineer to come up with a reproducing example in about 5 minutes.   But now I'm just being a curmudgeon.  :-) 

0

Please sign in to leave a comment.