﻿# V6133\. Dereferencing the parameter without a null check\. Passing the 'null' value to the 'equals' method should not cause 'NullPointerException'\.

The analyzer detected that the overridden equals method lacks a null check for the argument, violating the standard contract\.

Look at the example:

```cpp
@Override
public boolean equals(Object object) {
  if (this == object) {
    return true;
  }

  if (getClass() != object.getClass()) {
    return false;
  }

  Foo another = (Foo) object;
  return type.equals(another.type) &&
         name.equals(another.name);
}
```

The `equals` method implements a class match check and field comparison\. However, the developer did not take into account that the argument could be a null reference\. This may result in a [`NullPointerException`](https://docs.oracle.com/javase/8/docs/api/java/lang/NullPointerException.html) thrown when [`getClass`](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) is called\.

According to the documentation, overriding the [`Object.equals`](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#equals(java.lang.Object)) method should return `false` when a null reference is passed, rather than throw an exception\. This is especially important if the class is used in collections\.

The fixed example:

```cpp
@Override
public boolean equals(Object object) {
  if (this == object) {
    return true;
  }

  if (object == null || getClass() != object.getClass()) {
    return false;
  }

  Foo another = (Foo) object;
  return type.equals(another.type) &&
         name.equals(another.name);
}
```