Inspectopedia 2024.3 Help

Incorrect 'MessageFormat' pattern

Reports incorrect message format patterns or incorrect indexes of placeholders

The following errors are reported:

  • Unparsed or negative index

  • Unclosed brace

  • Unpaired quote. In this case, a part of a pattern may not be used

  • Probably incorrect number of quotes

  • Incorrect lower bound of nested choice patterns

  • Incorrect indexes of placeholders. In this case, a placeholder may not be substituted or an argument may not be used

Examples:

MessageFormat.format("{wrong}", 1); // incorrect index MessageFormat.format("{0", 1); // Unmatched brace MessageFormat.format("'{0}", 1); // Unpaired quote MessageFormat.format("It''''s {0}", 1); // "It''s" will be printed, instead of "It's" MessageFormat.format("{0}", 1, 2); // The argument with index '1' is not used in the pattern

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.

IncorrectMessageFormat
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 | Probable bugs

Use the Custom MessageFormat methods table to specify method calls that should have their arguments checked as MessageFormat patterns. The table contains pairs of fully qualified class name and method name regular expression to match the containing class and name of the method calls. Class names also match subclasses.

New in 2023.2

Inspection options

Here you can find the description of settings available for the Incorrect 'MessageFormat' pattern inspection, and the reference of their default values.

Custom MessageFormat methods

None

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.3, Qodana for JVM 2024.3,

Can be installed with plugin:

Java, 243.23126

Last modified: 03 December 2024