Inspectopedia Help

Hardcoded file separator

Reports the forward (/) or backward (\) slash in a string or character literal. These characters are commonly used as file separators, and portability may suffer if they are hardcoded.

The inspection will not report backward slashes inside escape sequences and forward slashes immediately following the '<' character or immediately preceding the '>' character, as those often indicate XML or HTML tags rather than file names. Strings representing a java.util.TimeZone ID, strings that are valid regular expressions, or strings that equal IANA-registered MIME media types will not be reported either.

Example:

new File("C:\\Users\\Name");

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.

HardcodedFileSeparator
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 | Java | Portability

Use the option to include example/* in the set of recognized media types. Normally, usage of the example/* MIME media type outside of an example (e.g. in a Content-Type header) is an error.

Inspection options

Here you can find the description of settings available for the Hardcoded file separator inspection, and the reference of their default values.

Include 'example/*' in recognized MIME media types

Not selected

Ignore arguments for the following methods

None

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.2, Qodana for JVM 2024.2,

Can be installed with plugin:

Java, 242.22892

Last modified: 11 September 2024