Skip to content

BSL260 — Unsafe FindByCode() method usage

Summary

Unsafe FindByCode() method usage

Identifiers

Field Value
Rule code BSL260
Compatible alias UnsafeFindByCode
Severity WARNING
Enabled by default Yes
Implemented Yes
Tags correctness, robustness

Behavior

  • The public identifier BSL260 and alias UnsafeFindByCode are stable.
  • The rule reports the cases documented on this page.
  • Suppressions and project configuration are applied before publication.
  • The rule requires neither an external analyzer nor network access.

Configuration and suppression

BSL### is the primary stable identifier. The compatible alias is accepted in select, ignore, and compatible block suppression comments.

[tool.onec-hbk-bsl]
select = ["BSL260"]
ignore = ["UnsafeFindByCode"]

All three suppression families support both a current line and a range. When an opening comment follows code, it affects only that line. Use any one form:

  • noqa:
Value = "example";  // noqa: BSL260
  • bsl-disable:
Value = "example";  // bsl-disable: BSL260
  • compatible BSLLS form:
Value = "example";  // BSLLS:UnsafeFindByCode-off

When the same opening comment is on a line by itself, it starts a range. Close it with the matching marker from the same family:

// noqa: BSL260
// code without this diagnostic
// noqa-enable: BSL260

// bsl-disable: BSL260
// code without this diagnostic
// bsl-enable: BSL260

// BSLLS:UnsafeFindByCode-off
// code without this diagnostic
// BSLLS:UnsafeFindByCode-on

To disable the rule until the end of the file, omit the closing noqa-enable, bsl-enable, or BSLLS:…-on marker.

Opening and closing markers must belong to the same family.

Description

The diagnostic detects the use of the FindByCode() method (or НайтиПоКоду()) for catalogs that have:

  • code uniqueness control disabled (the Check unique property is set to False)
  • or code series enabled not for the entire catalog (the Code series property is not equal to Whole catalog)

In such cases, using the FindByCode() method can lead to unexpected behavior, as the code may not be unique within the entire catalog or there may be multiple elements with the same code in different series.

Examples

Incorrect:

// Catalog without uniqueness control
CatalogWithoutControl = Catalogs.CatalogWithoutUniquenessControl.FindByCode("001");
// Catalog with code series "Within subordination"
CatalogWithSeries = Catalogs.CatalogWithSubordinationSeries.FindByCode("001");

Correct:

// Using FindByCode() method for catalog with uniqueness control
// and code series for the entire catalog
CatalogWithControl = Catalogs.CatalogWithUniquenessControl.FindByCode("001");
// Alternative option - use FindByName() method or other search methods
Catalog = Catalogs.CatalogWithoutUniquenessControl.FindByName("Element");

Sources