Java


JAVA.CONCURRENCY.UG.PARAM : Unguarded Parameter (Java)

Summary

A parameter of a method or constructor is accessed without the expected lock being held.

Java uses synchronized statements and methods to guarantee that data is accessed in a sequential way and avoid race conditions in multithreaded applications. Incorrect uses of synchronization result in unexpected behaviors and subtle bugs, very hard to identify and reproduce.

Checks for this warning class make use of annotations @com.juliasoft.julia.checkers.guardedBy.GuardedBy and @com.juliasoft.julia.checkers.guardedBy.Holding. Add these annotations to your code to identify synchronization requirements for CodeSonar to check.

The @GuardedBy annotation for fields and parameters and the @Holding annotation for methods and constructors accept a string argument, according to the following syntax.

Properties

Class Name Unguarded Parameter (Java)
Significance reliability
Mnemonic JAVA.CONCURRENCY.UG.PARAM
Categories
CWE CWE:366 Race Condition within a Thread
  CWE:567 Unsynchronized Access to Shared Data in a Multithreaded Context
CERT-Java CERT-Java:VNA00-J Ensure visibility when accessing shared primitive variables
Availability Available for Java only.
Enabling Checks for this warning class are disabled by default. To enable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Unguarded Parameter (Java)"

Resolution

Verify if the missing synchronization should actually be there. Annotate fields and methods with the lock that must be held when they are accessed or called, by using the @GuardedBy and @Holding annotations. If this checker does not accept those annotations, it is likely the case that your program has a synchronization problem.

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.