---
title: "CWE-486: Comparison of Classes by Name"
url: https://radicalnotion.ai/cwe/cwe-486
type: cwe
description: "The product compares classes by name."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-486: Comparison of Classes by Name

- **Abstraction:** Variant
- **Structure:** Simple
- **Status:** Draft
- **Likelihood of exploit:** High
- **CVEs with this as primary weakness:** 1
- **Of those, in CISA KEV:** 0
- **New in 2026:** 1
- **CWE catalog version:** 4.21

## Description

The product compares classes by name.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | - |

## Applicable platforms

**Languages:** Java (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity, Confidentiality, Availability | Execute Unauthorized Code or Commands | The product could use the wrong class. If the decision to trust the methods and data of an object is based on the name of a class, it is possible for malicious users to send objects of the same name as trusted classes and thereby gain the trust afforded to known classes and types. |

## Potential mitigations

### Implementation

Use class equivalency to determine type. Rather than use the class name to determine if an object is of a given type, use the getClass() method, and == operator.

## Detection methods

### Automated Static Analysis

Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

Effectiveness: High

## Demonstrative examples

### Example 1

In this example, the expression in the if statement compares the class of the inputClass object to a trusted class by comparing the class names.

Bad code:

```java
if (inputClass.getClass().getName().equals("TrustedClassName")) {

    // Do something assuming you trust inputClass

    // ...
}
```

Good code:

```java
if (inputClass.getClass() == TrustedClass.class) {

    // Do something assuming you trust inputClass

    // ...
}
```

However, multiple classes can have the same name therefore comparing an object's class by name can allow untrusted classes of the same name as the trusted class to be use to execute unintended or incorrect code. To compare the class of an object to the intended class the getClass() method and the comparison operator "==" should be used to ensure the correct trusted class is used, as shown in the following example.

### Example 2

In this example, the Java class, TrustedClass, overrides the equals method of the parent class Object to determine equivalence of objects of the class. The overridden equals method first determines if the object, obj, is the same class as the TrustedClass object and then compares the object's fields to determine if the objects are equivalent.

Bad code:

```java
public class TrustedClass {
    ...

    @Override
    public boolean equals(Object obj) {
        boolean isEquals = false;

        // first check to see if the object is of the same class
        if (obj.getClass().getName().equals(this.getClass().getName())) {

            // then compare object fields
            ...
            if (...) {
                isEquals = true;
            }
        }

        return isEquals;
    }

    ...
}
```

Good code:

```java
public boolean equals(Object obj) {
    ...

    // first check to see if the object is of the same class
    if (obj.getClass() == this.getClass()) {
        ...
    }

    ...
}
```

However, the equals method compares the class names of the object, obj, and the TrustedClass object to determine if they are the same class. As with the previous example using the name of the class to compare the class of objects can lead to the execution of unintended or incorrect code if the object passed to the equals method is of another class with the same name. To compare the class of an object to the intended class, the getClass() method and the comparison operator "==" should be used to ensure the correct trusted class is used, as shown in the following example.

## Real CVEs with this weakness

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2026-133078 | - | high | 7.2 | - | No | 2026-11-19 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-1025](https://radicalnotion.ai/cwe/cwe-1025) | Comparison Using Wrong Factors |
| Peer | [CWE-386](https://radicalnotion.ai/cwe/cwe-386) | Symbolic Name not Mapping to Correct Object |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| 7 Pernicious Kingdoms | Comparing Classes by Name | - | - |
| CLASP | Comparing classes by name | - | - |
| The CERT Oracle Secure Coding Standard for Java (2011) | Compare classes and not class names | OBJ09-J | - |
| Software Fault Patterns | Glitch in computation | SFP1 | - |

## Frequently asked questions

### What is CWE-486?

The product compares classes by name.

### What CVEs are caused by CWE-486?

1 recorded CVE is attributed to CWE-486: CVE-2026-133078.

### How do you prevent CWE-486?

Use class equivalency to determine type. Rather than use the class name to determine if an object is of a given type, use the getClass() method, and == operator.

### How is CWE-486 detected?

Automated Static Analysis: Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

### What are the consequences of CWE-486?

Exploiting CWE-486 can lead to: Execute Unauthorized Code or Commands.

### Is CWE-486 actively exploited?

1 recorded CVE is caused by CWE-486; it is not currently in CISA's KEV catalog of actively exploited flaws.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/486.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-486). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
