Java


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

要旨

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.

プロパティ

クラス名 Unguarded Parameter (Java)
日本語クラス名 Unguarded Parameter (Java)
クラス分類 信頼性 (reliability)
ニーモニック JAVA.CONCURRENCY.UG.PARAM
カテゴリー
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
対応言語 Java で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっています。チェックを有効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += allow class="Unguarded Parameter (Java)"

解決法

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.

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。