# VNX-1097: Persistent Storable Data Element without Associated Comparison Control Element

A class that defines an ordering without the matching equality.

| Field | Value |
|---|---|
| Rule ID | `VNX-1097` |
| Severity | Low |
| SARIF level | `note` |
| Kind | `sast` |
| Languages | Java, Kotlin, Python |
| CWE | [CWE-1097](https://cwe.mitre.org/data/definitions/1097.html) |
| CAPEC | [CAPEC-66](https://capec.mitre.org/data/definitions/66.html) |
| ATT&CK | [T1190](https://attack.mitre.org/techniques/T1190/) |
| CWSS vector | `CWSS:1.0/TI:L/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:L/DI:H/EX:L/EC:N/P:L` |
| Tags | `equality` `comparison` `reliability` `cwe-1097` |
| Source | [`internal/sast/rules/vnx-1097.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-1097.rego) |

## Overview

VNX-1097 maps to [CWE-1097: Persistent Storable Data Element without Associated Comparison Control Element](https://cwe.mitre.org/data/definitions/1097.html). It reports a class whose comparison controls are incomplete: the class can be ordered, but equality was never defined to agree with that order.

## Why this matters

Sorted structures (`TreeSet`, `TreeMap`, `bisect`, sorted de-duplication) treat two objects that compare as 0 as the same element. `==`, `HashSet` and `dict` keep using identity. The same pair of objects is then one entry in one collection and two in another, so lookups, de-duplication and stored copies disagree depending on which structure holds them. `functools.total_ordering` documents that the class must still supply `__eq__`.

Not reported: classes that also define equality, Java records and enums, Kotlin data classes, Python dataclasses and attrs classes, classes that extend another class (equality may be inherited), interfaces, and comments. The pairing of `equals()` with `hashCode()` is reported by [VNX-581](/sast/rules/vnx-581.md).

## What gets flagged

```java
public final class Version implements Comparable<Version> {
    @Override
    public int compareTo(Version other) {          // FLAGGED: no equals(Object)
        return Integer.compare(major, other.major);
    }
}
```

```python
@functools.total_ordering
class Money:
    def __lt__(self, other):                       # FLAGGED: no __eq__
        return self.cents < other.cents
```

## Remediation

1. Define `equals` (and `hashCode`) or `__eq__` (and `__hash__`) over the same fields the ordering compares.
2. In Kotlin or Python, a data class or `@dataclass(order=True)` generates both consistently.
3. For a confirmed false positive, add a `vulnetix-ignore: VNX-1097` comment on the line.

## References

- [CWE-1097: Persistent Storable Data Element without Associated Comparison Control Element](https://cwe.mitre.org/data/definitions/1097.html)
- [java.lang.Comparable: consistent with equals](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Comparable.html)
- [functools.total_ordering](https://docs.python.org/3/library/functools.html#functools.total_ordering)

## Suppressing this rule

Put a `nosec` comment on the line, or on line 1 to cover the whole file. Use the comment marker of the file's language (`#`, `//`, `--` or `;`):

```text
# nosec vnx-1097
// nosec vnx-1097
```

Or record an ignore rule: `vulnetix ignore add --rule vnx-1097 --reason "..."`. See [Suppressing findings](/sast/guides/suppressing-findings.md).
