# VNX-1024: Comparison of incompatible types (always false)

Reports Java equals() between a declared type and a literal of another type (String vs number, Long vs int literal.

| Field | Value |
|---|---|
| Rule ID | `VNX-1024` |
| Severity | Low |
| SARIF level | `note` |
| Kind | `sast` |
| Languages | Java, Python |
| CWE | [CWE-1024](https://cwe.mitre.org/data/definitions/1024.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 | `comparison-of-incompatible-types` `always-false` `cwe-1024` |
| Source | [`internal/sast/rules/vnx-1024.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-1024.rego) |

## Overview

VNX-1024 maps to [CWE-1024: Comparison of Incompatible Types](https://cwe.mitre.org/data/definitions/1024.html). It reports equality checks that can never be true because the two sides have different types:

- **Java:** `x.equals(y)` or `Objects.equals(x, y)` where `x` is declared in the file with exactly one type and `y` is a literal of another: a `String` against a number, boolean or char; a `Long` against an int literal (`5` boxes to `Integer`, which never equals a `Long`) or a string; an `Integer`/`Short`/`Byte` against a long, decimal or string; a `Double`/`Float` against an int or string; a `Boolean`, `Character`, `BigDecimal`, `BigInteger` or `UUID` against a string; and `"literal".equals(number)`.
- **Python:** a value read as a string (`input()`, `sys.argv[...]`, `os.environ.get`, `os.getenv`, Flask `request.args/form/headers/cookies`, Django `request.GET/POST`) compared with `==`/`!=` to an int or float literal, directly or through a variable assigned from it a few lines above and not converted since.

Not reported: names declared with more than one type in the file, `request.args.get(..., type=int)`, a `.get()` or `os.getenv()` with a numeric default, values converted with `int()`/`float()`/`len()`, ordering comparisons, comments and string literals.

## Why this matters

A check that is constantly false silently disables what it guards (an admin gate that never opens is harmless; a "deny if role == 0" that never fires is not), and a negated one is constantly true.

## What gets flagged

```java
private Long ownerId;
return ownerId.equals(0);        // Integer 0 never equals a Long
if (level.equals(1)) { ... }     // level is a String
```

```python
role = request.args.get("role")
if role == 1:                    # a str never equals an int
    return grant()
```

## Remediation

1. Compare values of the same type: parse the string first (`Integer.parseInt`, `int()`), or compare with a literal of the right type (`0L`, `"1"`).
2. In Flask, read typed parameters with `request.args.get(name, type=int)`.

## References

- [CWE-1024](https://cwe.mitre.org/data/definitions/1024.html)
- [SEI CERT EXP03-J: Do not use the equality operators when comparing values of boxed primitives](https://wiki.sei.cmu.edu/confluence/display/java/EXP03-J.+Do+not+use+the+equality+operators+when+comparing+values+of+boxed+primitives)

## 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-1024
// nosec vnx-1024
```

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