Inspectopedia 2024.3 Help

Locks mistakenly passed by value

Reports locks that are mistakenly passed by values.

Accidentally copying a value containing a lock may cause both copies to work incorrectly. Generally, such values should be referred to through a pointer. A lock here means a type implementing sync.Locker, such as sync.Mutex or sync.WaitGroup.

Example:

type SafeInt struct { m sync.Mutex i int } func (s SafeInt) Inc() { // mutex is copied s.m.Lock() s.i++ s.m.Unlock() }

After the Add pointer quick-fix is applied:

type SafeInt struct { m sync.Mutex i int } func (s *SafeInt) Inc() { s.m.Lock() s.i++ s.m.Unlock() }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

GoVetCopyLock
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Go | Probable bugs

Inspection Details

By default bundled with:

GoLand 2024.3, Qodana for Go 2024.3,

Can be installed with plugin:

Go, 243.23131

Last modified: 03 December 2024