# VNX-583: finalize() method declared public

Reports Java overrides of Object.finalize() declared public and Kotlin member finalize() functions left at the default public visibility. Protected finalizers.

| Field | Value |
|---|---|
| Rule ID | `VNX-583` |
| Severity | Medium |
| SARIF level | `warning` |
| Kind | `sast` |
| Languages | Java, Kotlin |
| CWE | [CWE-583](https://cwe.mitre.org/data/definitions/583.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:M/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:M/DI:H/EX:M/EC:N/P:C` |
| Tags | `finalize-public` `cwe-583` |
| Source | [`internal/sast/rules/vnx-583.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-583.rego) |

## Overview

VNX-583 maps to [CWE-583: finalize() Method Declared Public](https://cwe.mitre.org/data/definitions/583.html). It reports a Java `void finalize()` declaration with no parameters whose modifiers include `public`, in any order and after annotations, and a Kotlin member `fun finalize()` with no visibility modifier or with `public` (Kotlin members are public by default).

## Why this matters

`Object.finalize()` is protected. Widening it to public lets any caller run the finalizer, which typically frees native memory or closes handles, while the object is still in use. A later access then works on released resources.

## What gets flagged

```java
public void finalize() throws Throwable {
public synchronized void finalize() {
@Override public void finalize()
```

```kotlin
class NativeHandle(private val ptr: Long) {
    fun finalize() { Native.free(ptr) }
}
```

Not flagged: `protected void finalize()`, Kotlin `protected fun finalize()` and top-level `fun finalize()`, `public void finalize(int code)`, `public void finalizeOrder()`, calls such as `s.finalize()`, comments, strings and test files.

## Remediation

1. Declare the override `protected`, as `Object.finalize()` is.
2. Prefer `AutoCloseable` with try-with-resources, or `java.lang.ref.Cleaner`; finalization is deprecated for removal.

## References

- [CWE-583: finalize() Method Declared Public](https://cwe.mitre.org/data/definitions/583.html)
- [SEI CERT MET12-J: Do not use finalizers](https://wiki.sei.cmu.edu/confluence/display/java/MET12-J.+Do+not+use+finalizers)

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

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