Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Find Bugs reports get method should be made synchronized  RSS feed

 
Ron McLeod
Saloon Keeper
Posts: 1600
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am seeing this issue reported by Find Bugs:

Bug: gpio.ITE8528Gpio.get() is unsynchronized, gpio.ITE8528Gpio.set(int, int) is synchronized

This class contains similarly-named get and set methods where the set method is synchronized and the get method is not.  This may result in incorrect behavior at runtime, as callers of the get method will not necessarily see a consistent state for the object.  The get method should be made synchronized.

Rank: Troubling (14), confidence: Normal
Pattern: UG_SYNC_SET_UNSYNC_GET
Type: UG, Category: MT_CORRECTNESS (Multithreaded correctness)


Is this a false positive, or am I missing something?  It seems like it is comparing a non-synchronized convenience getter method against a synchronized setter method and determining that my convenience method should to be synchronized to match.

 
Dave Tolls
Rancher
Posts: 2914
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like a false positive.
It's attempting to pair up the get's with set's and looks to be getting it wrong.

As a test you could (temporarily) rename the non-synchornised get and set to something else (getDefault, setDefault?)...that should confirm it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!