JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.0p0 Hot Tips | CONFIDENTIAL | CodeSecure Inc |
A file name is provided as a hardcoded string.
This checker identifies problems with the use of the external resources of the application. These are resource files, scripts or XML configuration files.
| クラス名 | Hardcoded Filename (Java) | |||
|---|---|---|---|---|
| 日本語クラス名 | Hardcoded Filename (Java) | |||
| クラス分類 | 信頼性 (reliability) | |||
| ニーモニック | JAVA.HARDCODED.FNAME | |||
| カテゴリー |
|
|||
| 対応言語 | Java で利用可能です。 |
|||
| 有効/無効設定 | このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル
(configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Hardcoded Filename (Java)" |
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
public class Resources {
public static void main(String[] args) throws FileNotFoundException {
new File("hello.txt"); // "Hardcoded Filename (Java)" warning issued here
new FileInputStream("C:\\myfile.txt"); // "Hardcoded Filename (Java)" warning issued here
new FileOutputStream("/home/spoto/myfile.bmp"); // "Hardcoded Filename (Java)" warning issued here
if (args.length > 0)
new File(args[0]);
}
}
Aside from the security risks associated with hardcoded file names, it is worth noting that paths "C:\\myfile.txt" and "/home/spoto/myfile.bmp" are OS-dependent: this program will not work consistently across all operating systems.
In this example, the programmer should move the file names into configuration files, so that they can be modified and swapped for distinct operating systems. It is also good practice to use File.separatorChar() to split path components in a OS-independent way.
Verify if the problem is real and the resource is actually used in an incorrect way. Avoid hardcoded file names: move them to a configuration file. Avoid OS-dependent resources and resource names.
設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。